SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Column Exists or not?


Column Exists or not?

Author
Message
Shiva N
Shiva N
SSCrazy
SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)SSCrazy (2.4K reputation)

Group: General Forum Members
Points: 2385 Visits: 470
Comments posted to this topic are about the item Column Exists or not?

Thanks,
Shiva N
Database Consultant
octavian.zaharia
octavian.zaharia
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 43
Interesting function, but I suggest to modify the code to add the schema to the existence check because you can have two tables with the same name, one for input and one for logging incorrect data. Also I would suggest to add a join to the INFORMATION_SCHEMA.TABLES in order to be know you are interested in a table not a view.

So the select statement should be
SELECT 1
FROM INFORMATION_SCHEMA.Columns C
JOIN INFORMATION_SCHEMA.TABLES T ON C.TABLE_NAME = T.TABLE_NAME
WHERE T.TABLE_NAME = @TableName AND T.SCHEMA_NAME = @SchemaName AND
AND COLUMN_NAME = @ColumnName and T.TABLE_TYPE = 'BASE TABLE'
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search