CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets matching tags of sql server
SQL
select name as 'Database Name', [dbid] from master.dbo.sysdatabases
by Egli   November 09, 2011 @ 4:56pm
67 Views
no comments
 
SQL
/*
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'
by Egli   November 01, 2011 @ 5:33pm
64 Views
no comments
 
SQL
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 
by Egli   August 17, 2011 @ 5:50am
132 Views
no comments
 
SQL
/*
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
by Egli   July 26, 2011 @ 12:52am
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
by Jon Sagara   December 27, 2010 @ 5:43pm
181 Views
no comments
 
C#
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))
by Jon Sagara   April 25, 2010 @ 1:14am
313 Views
no comments
 
SQL
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
by kopelli   December 31, 2009 @ 6:32am
183 Views
no comments
 
SQL
CREATE TABLE SomeBaseTable
(
 BatchId int NOT NULL PRIMARY KEY,
 BatchName varchar(250) NOT NULL,
 AnIntParameter int NULL,
 AnotherIntParameter int NULL
)
GO
 
INSERT INTO SomeBaseTable
by Luciano Evaristo Guerche (Gorše)   October 21, 2009 @ 7:50am
477 Views
1 comments
 
SQL
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
 
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate