dbTalk Databases Forums  

DROP COLUMN

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss DROP COLUMN in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Jose Nunez
 
Posts: n/a

Default DROP COLUMN - 11-25-2007 , 04:13 PM






If I execute ALTER TABLE DROP COLUMN XX but the column XX has Constraints
there will be an error.

I should first delete the related Constraints.

Is there any way to delete all of the Constraints related to this column?

Should I navigate before for all of the constraints of the table and delete
the related ones? In this case, how could I do this in VB?

Regards.
Jose Nuņez
Montevideo



Reply With Quote
  #2  
Old   
Russell Fields
 
Posts: n/a

Default Re: DROP COLUMN - 11-26-2007 , 10:23 AM






Jose,

The INFORMATION_SCHEMA view contain what you are after. Here is a sample
query that may be helpful to you:

select y.TABLE_NAME AS ConstrainingTable, x.CONSTRAINT_NAME AS
ConstraintToDisable,
z.TABLE_NAME AS ConstrainedTable, zz.COLUMN_NAME as ConstrainedColumn,
z.CONSTRAINT_NAME AS ConstrainedConstraint
from INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS x
join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE y
on x.CONSTRAINT_NAME = y.CONSTRAINT_NAME
join INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE z
join INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE zz
on z.CONSTRAINT_NAME = zz.CONSTRAINT_NAME
on x.UNIQUE_CONSTRAINT_NAME = z.CONSTRAINT_NAME
where y.COLUMN_NAME = 'MyKeyColumn' and z.TABLE_NAME = 'MyConstrainedTable'


RLF

"Jose Nunez" <josenunez70 (AT) hotmail (DOT) com> wrote

Quote:
If I execute ALTER TABLE DROP COLUMN XX but the column XX has Constraints
there will be an error.

I should first delete the related Constraints.

Is there any way to delete all of the Constraints related to this column?

Should I navigate before for all of the constraints of the table and
delete the related ones? In this case, how could I do this in VB?

Regards.
Jose Nuņez
Montevideo




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.