Вопрос

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

Это было полезно?

Решение

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

Другие советы

alter table TABLE1
alter column [CustomerVLANID] int not null

I hope this helps,

-Thomas RosSQL.blogspot.com

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top