How to define a primary key using SQL

advertisements

I have this table 'Cars', attributes:

MODEL nvarchar(20)
STYLE nvarchar(20)
ENGINE nvarchar(5)
CAPACITY smallint
MAX_SPEED smallint
PRICE smallmoney
MARKET nvarchar(20)
COMPETITOR nvarchar(20)

I would like to set 'PRICE' as the primary key via a SQL sStatement, so I've tried:

ALTER TABLE Cars
ADD PRIMARY KEY (PRICE)

But I just get the error

The ALTER TABLE SQL construct or statement is not supported.

in Visual Studio 2010.


As has been said above, price is a bad primary key. But ... the correct syntax to do what you are trying to do is:

ALTER TABLE Cars
ADD CONSTRAINT cars_pk PRIMARY KEY (PRICE)