|
-
Oct 14th, 2004, 02:24 AM
#1
Thread Starter
Lively Member
SQL Query Problem
Using Query Analyzer, I am getting some results I have not seen before.
Any help that you can offer would be greatly appreciated.
Adding the Column works fine:
Code:
ALTER TABLE [dbo].[tblSaleItem] ADD [Temp_Qty] [float] DEFAULT 0 NOT NULL
Attempting to drop a column in a valid table using;
Code:
ALTER TABLE [dbo].[tblSaleItem] DROP COLUMN [Temp_Qty]
Gets the following error:
Server: Msg 5074, Level 16, State 1, Line 1
The object 'DF__tblSaleIt__Temp___07EC11B9' is dependent on column 'Temp_Qty'.
Server: Msg 4922, Level 16, State 1, Line 1
ALTER TABLE DROP COLUMN Temp_Qty failed because one or more objects access this column.
When I add the new column it appears to automatically add the default constraint shown above (DF__tblSaleIt__Temp___07EC11B9)
I just add the column and then try to drop it as a test and it causes this error.
-
Oct 14th, 2004, 06:50 AM
#2
Fanatic Member
Basically, a default in sql server is a constraint and this is why it is getting created. This applies whether you add the column through Enterprise Manager or Query Analyser.
The difference comes when you want to drop the column. If you use EM, then it drops the constraint automatically, however if you use QA, then you'll have to manually drop the constraint before you can drop the column (as you are seeing!)
so, you just need to put:
Code:
ALTER TABLE Temp_QTY DROP CONSTRAINT [DF__tblSaleIt__Temp___07EC11B9]
before you can drop the column (or just drop it through EM!).
-
Oct 14th, 2004, 07:51 PM
#3
Thread Starter
Lively Member
thanks for that blade.
So, programmically, how would I know what the name of the constraint (that is automatically created) is?
If I know this then I can delete it...
Thank you in advance,
Nightshift
-
Oct 15th, 2004, 07:16 AM
#4
Fanatic Member
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
|
Click Here to Expand Forum to Full Width
|