stackemedia

Re-seeding a table id (SQL)

This was posted in SQL on June 17th, 2009

Use the code below if you want to restart the id column of a table from 0.
This is most useful if you have cleared a table and want to have the automatic generation of the id field to start at zero again.

DBCC CHECKIDENT(‘yourTable’, RESEED, 0) ;

Check if a column exists and delete it (SQL)

This was posted in SQL on June 17th, 2009

Exactly what the title says, checks if a column exists and then deletes it.

IF exists(SELECT id FROM syscolumns WHERE name LIKE ‘yourColumn’)
ALTER TABLE yourTable DROP COLUMN yourColumn

Get the day of the week (SQL)

This was posted in SQL on June 17th, 2009

Use to find the day of the week and return an integer.

SELECT TOP(5) DatePart(WEEKDAY, [EnquiryRaisedDate]) AS ‘DayOfWeek’, [EnquiryRaisedDate] FROM [vEnquiry]

To find the named day of the week, use:

SELECT TOP(5) DateName(WEEKDAY, [EnquiryRaisedDate]) AS ‘DayOfWeek’, [EnquiryRaisedDate] FROM [vEnquiry]

Tested browsers: firefox, chrome, IE8