Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IF EXISTS ( SELECT * FROM INFORMATION_SCHEMA.COLUMNS
- WHERE TABLE_NAME='tablename' AND COLUMN_NAME='columname' )
- SELECT count(*) AS [Column Exists]
- FROM SYSOBJECTS
- INNER JOIN SYSCOLUMNS ON SYSOBJECTS.ID = SYSCOLUMNS.ID
- WHERE
- SYSOBJECTS.NAME = 'myTable'
- AND SYSCOLUMNS.NAME = 'Myfield'
- If col_length('table_name','column_name') is null
- select 0 as Present
- ELSE
- select 1 as Present
- if COLUMNPROPERTY(object_id('table_name'), 'column_name', 'ColumnId') is null
- print 'doesn't exist'
- else
- print 'exists'
Add Comment
Please, Sign In to add comment