Question

I have the following table in SQL Server 2008 R2

enter image description here

Now I need to write a script to add a new column cusomerVLANID as part of the primary key, so that the three columns becomes the primary key, is there a way to write such script.

Second thing I want to write a script to remove the Allow Null, check box from the CustomerVLANID columns ?

Thanks

Was it helpful?

Solution

ALTER TABLE <Table_Name>
DROP CONSTRAINT <constraint_name>

ALTER TABLE <Table_Name>
ADD CONSTRAINT <constraint_name> PRIMARY KEY ([ID], [CustomerName], [CustomerVLANSID])

Run this statement separately to set up the NOT NULL constraint:

ALTER TABLE <Table_Name>
ALTER COLUMN [CustomerVLANSID] INT NOT NULL

OTHER TIPS

alter table TABLE1
alter column [CustomerVLANID] int not null

I hope this helps,

-Thomas RosSQL.blogspot.com

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top