-
IF EXISTS Column (for MS SQL 2000)
Hello
How do you check if a column exist for MS SQL 2000 ?
for a table :
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[myTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[myTable]
GO
but I dont find it for a column
Thank you
-
Can query information_schema.columns.
-
? I dont understand the meaning of your answer
I got this code on another forum :
if exists ( select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='tablename'
and COLUMN_NAME='columname' )
drop table [dbo].[myTable]
but I want to drop the column not the table ?
then maybe :
if exists ( select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='tablename'
and COLUMN_NAME='columname' )
drop COLUMN 'columname'
thank you for helping
-
You can use 'alter table' to drop column. By the way, you original question is 'How do you check if a column exist for MS SQL 2000'.
-
oops ! yessorry !
then is that correct to drop a column if this colum exists ?
if exists ( select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='tablename'
and COLUMN_NAME='columname' )
drop COLUMN 'columname'
-
You have to use 'alter table table_name drop column column_name'.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|