Reputation: 45
I am using the alter command
to add a column with not null and default value to the sql,
but when i run it it also creates the constraint with some silly words, how can i use the alter command
to add the column also and also add the constraint with it with the name i specify
my alter is like this
ALTER TABLE users
ADD role bit not null default 0;
Should the combined constraint with same alter command will work, not sure how to add it
Upvotes: 0
Views: 15
Reputation: 69789
You can include the constraint name within the statement as follows:
ALTER TABLE users ADD role bit NOT NULL CONSTRAINT DF_Users__Role DEFAULT (0);
There are examples in the docs online, albeit a long way down the page: B. Adding a column with a constraint
Upvotes: 2