Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
problem with naming default constraint and...
problem with naming default constraint and using it while adding a not null column
Rate Topic
Display Mode
Topic Options
Author
Message
Amit kulkarni-491236
Amit kulkarni-491236
Posted Monday, November 05, 2007 2:10 AM
Mr or Mrs. 500
Group: General Forum Members
Last Login: Friday, June 24, 2011 9:55 AM
Points: 524,
Visits: 219
i have a table 'staff'... it already contains some 10-15 records
now i want to add a new column StaffCode to the table which is not null.... iam adding a default value otherwise it will throw error
the syntax is:
ALTER TABLE Staff ADD StaffCode varchar(10) DEFAULT ' ' NOT NULL;
GO
iam able to create a default value and add the column but i want to change the name of default constraint... how to do it...
i tried the following steps
ALTER TABLE Staff ADD StaffCode varchar(10)NULL;
GO
ALTER TABLE Staff ADD CONSTRAINT Staff_StaffCode_df DEFAULT ' '
FOR StaffCode
GO
ALTER TABLE Staff ALTER COLUMN StaffCode varchar(10) NOT NULL;
GO
I get the error:-
Msg 4901, Level 16, State 1, Line 1
ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'StaffCode' cannot be added to non-empty table 'Staff' because it does not satisfy these conditions.
Please help.... iam able to give default value but not able to give my own constraint name
Post #418412
Ramesh Saive
Ramesh Saive
Posted Monday, November 05, 2007 2:32 AM
SSCrazy
Group: General Forum Members
Last Login: Friday, February 22, 2013 12:03 AM
Points: 2,555,
Visits: 2,587
ALTER TABLE Staff ADD StaffCode varchar(10) NOT NULL CONSTRAINT Staff_StaffCode_df DEFAULT(' ');
--Ramesh
Post #418419
Amit kulkarni-491236
Amit kulkarni-491236
Posted Monday, November 05, 2007 3:11 AM
Mr or Mrs. 500
Group: General Forum Members
Last Login: Friday, June 24, 2011 9:55 AM
Points: 524,
Visits: 219
thanks... i was able to get it
Regards,
Amit kulkarni
Post #418438
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.