Archive for the Category SQL Server

 
 

SQL Server: Search For Column In a Database

So let’s say you have a SQL Server db that contains 100 tables. You want to know which of these 100 tables contains a column of a certain name without poring through all 100 manually.

Use this syntax:

SELECT * FROM sysobjects
WHERE id IN ( SELECT id FROM syscolumns WHERE name = 'column_name_here' )

This only seems to search the db in current scope, not all the db’s in your particular SQL Server DBMS.

SQL Server: Add Identity Column To Existing Table

How to add a identity column to an existing table in MS SQL Server.


alter table table_name
add column_name int identity(1,1)