I want to add 2 new columns to existing table.
One of them should be NOT NULL
with default value 0 (filled in the existing rows as well).
I have tried the following syntax:
Alter TABLE dbo.MamConfiguration add [IsLimitedByNumOfUsers] [bit] NOT NULL, CONSTRAINT IsLimitedByNumOfUsers_Defualt [IsLimitedByNumOfUsers] DEFAULT 0 [NumOfUsersLimit] [int] NULL go
But it throws exception. How should I write it?
Multiple columns level constraints can be added via alter command. It can be added in parent-child table in a serial order. Parent having default constraint on ID with the default value 1.
SQL Add Multiple Columns to a Table. You can add multiple columns to an SQL table using the ALTER TABLE syntax. To do so, specify multiple columns to add after the ADD keyword. Separate each column you want to add using a comma.
You can use this:
ALTER TABLE dbo.MamConfiguration ADD [IsLimitedByNumOfUsers] [BIT] NOT NULL DEFAULT 0, [NumOfUsersLimit] [INT] NULL GO
or this:
ALTER TABLE dbo.MamConfiguration ADD [IsLimitedByNumOfUsers] [BIT] NOT NULL CONSTRAINT IsLimitedByNumOfUsers_Default DEFAULT 0, [NumOfUsersLimit] [INT] NULL go
More: ALTER TABLE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With