RSS

Check if column is Exists in table or not exists

30 Aug

declare @count int

Declare @table nvarchar (50)

declare @Column nvarchar (100)

set @table =‘checkcolumn’

set @Column =‘Salary’

set @count =(Select count(*) fromInformation_Schema.columns

where Table_name = @table and Column_name =@Column)

if (@count=1)

print ‘The Column Name ‘+‘ ( ‘+ @Column +  ‘ ) ‘+‘ Is already Exists in Table Name ‘+   ‘ ( ‘+ @table +  ‘ ) ‘

if (@count = 0)

print ‘The Column Name ‘+’ ( ‘+ @Column +  ‘ ) ‘+’ Is Not Exists in Table Name ‘+   ‘ ( ‘+ @table +  ‘ )

 
Leave a comment

Posted by on August 30, 2011 in Script

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s