Scripts

Technical Article

Script to kill the top blocker and report what it was doing.

This script identifies the blocking locks at the top of the blocking chain and kills them. Specifically, it reports what the top blocking spids are doing, kills them, waits three seconds and then reports on current blocking status.  If you have a situation where single connections are causing a huge blocking chain and you want […]

4.75 (4)

You rated this post out of 5. Change rating

2003-05-12

4,364 reads

Technical Article

How to get ColumnNames, datatypes and length

This is a followup to the script submitted by srallapalli. One can return a record set of all tables in a database using the following:USE MyDatabaseSELECT so.name AS TableName, sc.name AS ColumnName,  st.name AS ColumnDatatype,  convert(int, sc.length) AS ColumnLength FROM syscolumns sc, sysobjects so , systypes st WHERE so.type='U' AND OBJECTPROPERTY(so.id,'ismsshipped') = 0 AND sc.id=so.id […]

You rated this post out of 5. Change rating

2003-05-10

144 reads

Technical Article

Generate "CREATE...FOR ATTACH" stmt. dynamically

In instances where you have over 16 data files, or you need to move data files to a new location when you are moving a database you must use a CREATE...FOR ATTACH statement.  This script will generate the CREATE...FOR ATTACH statement dynamically given a database name.  It will take into consideration the file sizes, growths […]

You rated this post out of 5. Change rating

2003-05-07

221 reads

Technical Article

Restrict simultaneous access to resources

This set of procedures allow you to control simultaneous access to any resource you are using. It mimics the behaviour of a Semaphore in programming.A typical problem where you need this, is when you have a computational intensive procedure you only want to be started a limited number of times.First, add a record to the […]

You rated this post out of 5. Change rating

2003-05-07

280 reads

Technical Article

Returning data with col number

This script enables you to return data from SQL Server's table without specyfing the name of the column .All you only need to supply is the column number, that you want the data from. In the example we want to chose all rows from the second column (categories table - northwind) Column number is based […]

You rated this post out of 5. Change rating

2003-05-07

166 reads

Technical Article

UDF to get first date or trim time for Datepart.

Not long ago I was in a forum discussion when someone presented another way to get the date with time value of midnight by doing similar to thisDATEADD(dd,DATEDIFF(dd,0,@DATE),0)Which I find is much cleaner than any other option I have seen or tried myself. Seeing this I realized there are many other dates that can be […]

4 (1)

You rated this post out of 5. Change rating

2003-05-02

477 reads

Blogs

Azure SQL offerings

By

There are three Azure SQL products with so many different deployment options, service tiers,...

T-SQL Tuesday #183 Roundup

By

I hosted this month’s T-SQL Tuesday party with my invitation asking about tracking permissions....

A Little Brainstorming with an AI

By

I was asked to do some a little thinking and brainstorming recently. Rather than...

Read the latest Blogs

Forums

Moving Database Files

By Ahr Aitch

I just learned that my database was created on my C:\ drive in the...

Migrate MSSQL to MYSQL - Different Servers

By cajun_sql

I am needing to migrate a MSSQL db to MySQL, on a different server...

how do you manage new columns in a tabular table

By stan

Hi we run 2019 ssas std.  Yesterday i imported my tabular project to vs...

Visit the forum

Question of the Day

Mixed Backups

I have a complex database with a few filegroups and files. Can I run a backup command like this? (assume file/filegroup names are valid).

BACKUP DATABASE [complex]
    FILE = N'thirdone'
 ,  FILE = N'thirdtwo'
 ,  FILEGROUP = N'second' 
 TO  DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL16.SQL2022\MSSQL\Backup\complex.bak' 
 WITH NOFORMAT, NOINIT,  NAME = N'complex-Full Database Backup', SKIP, NOREWIND, NOUNLOAD,  STATS = 10
GO

See possible answers