473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Drop Default Constraints

Hi

I am working on SQL SERVER 200 and I am trying to drop the default constraints set in few tables. I tired to follow the instructions given in MSDN for dropping a default:

1) Unbind the code

Expand|Select|Wrap|Line Numbers
  1.  Exec  sp_unbindefault 'tablename.columname' 
When I try to run it, it gives me following this error message:

Server: Msg 15049, Level 11, State 1, Procedure sp_unbindefault, Line 98
Cannot unbind from 'tablename.columname'. Use ALTER TABLE DROP CONSTRAINT.

2) AS ore the second step mentioned in MSDN and from the error message, I tired Alter table drop constraint

Expand|Select|Wrap|Line Numbers
  1.  ALTER TABLE tablename DROP DEFAULT [constraintname] 
Again an error message: Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'DEFAULT'.

3) So I try only to use drop default constraint

Expand|Select|Wrap|Line Numbers
  1.  DROP DEFAULT constraintname 
Third error message: Server: Msg 3716, Level 16, State 3, Line 1
The default 'constraintname' cannot be dropped because it is bound to one or more column.

Finally I read few more tutorial, though almost all said the same, I was inclined to try another syntax mentioned in one of them:

4)
Expand|Select|Wrap|Line Numbers
  1.  ALTER TABLE tablename ALTER COLUMN columname DROP DEFAULT constraintname 
This again gave me another error message as copied below: Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'DEFAULT'.

So finally I have run out of ideas and would be glad if anyone can be of some help. I am sure someone should have come across this issue and maybe found a work around.

Thanks a ton in advance :)
Sree
Oct 31 '07 #1
5 17248
debasisdas
8,127 Expert 4TB
Try to use

ALTER TABLE tablename DROP constraint constraintname

again the constraint can't be dropped if it has any dependency.
Oct 31 '07 #2
Try to use

ALTER TABLE tablename DROP constraint constraintname

again the constraint can't be dropped if it has any dependency.
Hi debasisdas,

Thanks for your quick response but thats what I have tried in code 2) I have listed in my original post. I thought you meant me to try:

Expand|Select|Wrap|Line Numbers
  1.  ALTER TABLE tablename DROP Constraint [constraintname]  
I got the following error message: Server: Msg 3728, Level 16, State 1, Line 1
'DF_Population_History_PPATIENTS' is not a constraint.
Server: Msg 3727, Level 16, State 1, Line 1
Could not drop constraint. See previous errors.

Than I tired this again
Expand|Select|Wrap|Line Numbers
  1.  DROP DEFAULT constraintname 
And surprisingly got this message: Server: Msg 3701, Level 11, State 5, Line 1
Cannot drop the default 'DF_Population_History_PPATIENTS', because it does not exist in the system catalog.


Than I checked the table and the constraint was gone, now I am not sure which one worked. I will try in few more and post it back.

Thanks
Sree
Oct 31 '07 #3
Hi Debasis,

Your code worked, I mean the DROP Constraint Constraintname, thought its still giving me the error message, when I actually go back and check the table, the constraint is gone.

I more of Idiosyncrasies of SQL Server 2000, hail MS ;)

Anyways, thanks a lot, it works even though it gives error message though I will glad to know why it acts like this.

Cheers
Sree
Oct 31 '07 #4
alter table [Table Name] drop column [Column Name]
Jul 26 '12 #5
Rabbit
12,516 Expert Mod 8TB
@9710682106, your answer is wrong. They want to drop constrainst, not columns. Also, the thread is over 4 years old.
Jul 26 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: James Knowlton | last post by:
Hello, I'm just returning to MS SQL Server after two years of dealing with Sybase ASE. I need to drop a column, using the alter table command. I keep getting an error indicating that a...
4
by: Johan Vervloet | last post by:
Does anybody know how I can change the default value for a column? I was trying to remove the default value in order to add the new one afterwards. This is what I tried: alter table...
1
by: jbtaylor16 | last post by:
I have several default constraints defined on a table. When I use the Object Browser and expand the constraints for this table and right-click and then select "Script Object to New Window As...
10
by: serge | last post by:
I am doing a little research on Google about this topic and I ran into this thread: ...
1
by: tchangmian | last post by:
I am using SQL Server 2000 and i would like to find out how to write the syntax in stored procedure for dropping the constraints within the table. Below is the request for my case: 1)Perform...
1
by: Igor Kryltsov | last post by:
Hi, I have table: # \d category; category_id | integer | not null default nextval('public.category_category_id_seq'::text) category_name | character varying(100) | not...
6
by: Giacomo | last post by:
Hi, I've the following problem. I must delete a column DEFAULT from a table, but I must do it with a script, independently from the server where it'll be executed. Locally I've tried with: ...
2
by: Eric Bragas | last post by:
Hi, I see the following in Books Online: CONSTRAINT--Is an optional keyword indicating the beginning of a PRIMARY KEY, NOT NULL, UNIQUE, FOREIGN KEY, or CHECK constraint definition... But I...
4
by: teddysnips | last post by:
A few weeks ago a client asked me to add a column to a table so I created this script: ALTER TABLE dbo.tblIndividual ADD fldRenewalStatus BIT NOT NULL CONSTRAINT fldRenewalStatus_Default DEFAULT...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.