Monthly Archives: January 2012

How do I determine if a table exists in a SQL Server database?

For Sql Server 2005 and onwards, we can use the below query: IF NOT EXISTS (SELECT 1 FROM sysobjects WHERE xtype=’u’ AND name=’TableName’) SELECT ‘TableName Created’ ELSE select ‘Table already exists’ Refer to example below : IF NOT EXISTS (SELECT … Continue reading

Posted in Knowledge Sharing | Leave a comment

How to Insert values into an Identity Column of a Table

Sometimes we need to create a backup of an existing table with same shema, containing the same data as the previous table. To create a table with same schema we can use the below script: SELECT * INTO dbo.EmployeeBackup FROM … Continue reading

Posted in Knowledge Sharing | Leave a comment