Format:
Recent snippets matching tags of sql server
select name as 'Database Name', [dbid] from master.dbo.sysdatabases
67 Views
no comments
/* Since you cant alter the database straight away, you first need to kill the user thats currently connected to it... So... Step 1: Get the session thats connected to that database */ select d.name, d.dbid, spid, login_time, nt_domain, nt_username, loginame from master.dbo.sysprocesses p inner join master.dbo.sysdatabases d on p.dbid = d.dbid where d.name = 'DATABASE NAME GOES HERE'
64 Views
no comments
CREATE Procedure spDeleteRows /* Recursive row delete procedure. It deletes all rows in the table specified that conform to the criteria selected, while also deleting any child/grandchild records and so on. This is designed to do the same sort of thing as Access's cascade delete function. It first reads the sysforeignkeys table to find any child tables, then deletes the soon-to-be orphan records from them using recursive calls to this procedure. Once all child records are gone, the rows are deleted from the selected table. It is designed at this time to be run at the command line. It could
132 Views
no comments
/* Only showing the top 100 for this result */ SELECT TOP(100) total_worker_time/execution_count AS AvgCPU , total_worker_time AS TotalCPU , total_elapsed_time/execution_count AS AvgDuration , total_elapsed_time AS TotalDuration , (total_logical_reads+total_physical_reads)/execution_count AS AvgReads , (total_logical_reads+total_physical_reads) AS TotalReads
102 Views
no comments
$dbDir = "C:\Dev\MyProject\branches\1.0.0\src\Database\" $viewsDir = [IO.Path]::Combine($dbDir, "Views") $functionsDir = [IO.Path]::Combine($dbDir, "Functions") $sprocsDir = [IO.Path]::Combine($dbDir, "Stored Procedures") $dbServer = "(local)\SQL2k8" #Write-Host $dbDir #Write-Host $viewsDir
181 Views
no comments
public class SqlAppender : AppenderSkeleton { private static readonly string CommandText = "INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)"; public string ConnectionString { get; set; } protected override void Append(LoggingEvent loggingEvent) { using (var conn = new SqlConnection(ConnectionString)) using (var cmd = new SqlCommand(CommandText, conn))
313 Views
no comments
DECLARE @str nvarchar(128) SET @str = '[AdventureWorks].[dbo].[ErrorLog]' SELECT ISNULL(PARSENAME(@str, 4), @@SERVERNAME) AS [ServerName], ISNULL(PARSENAME(@str, 3), DB_NAME()) AS [DatabaseName], ISNULL(PARSENAME(@str, 2), ISNULL([default_schema_name], 'dbo')) AS [SchemaName], PARSENAME(@str, 1) AS [ObjectName] FROM [sys].[database_principals] WHERE [name] = SYSTEM_USER
183 Views
no comments
CREATE TABLE SomeBaseTable ( BatchId int NOT NULL PRIMARY KEY, BatchName varchar(250) NOT NULL, AnIntParameter int NULL, AnotherIntParameter int NULL ) GO INSERT INTO SomeBaseTable
477 Views
1 comments
SELECT SERVERPROPERTY('BuildClrVersion') AS [BuildClrVersion] GO SELECT SERVERPROPERTY('Collation') AS [Collation] GO SELECT SERVERPROPERTY('CollationID') AS [CollationID] GO SELECT SERVERPROPERTY('ComparisonStyle') AS [ComparisonStyle] GO SELECT SERVERPROPERTY('ComputerNamePhysicalNetBIOS') AS [ComputerNamePhysicalNetBIOS] GO
472 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
