Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alter Table

Status
Not open for further replies.

JimReiley

MIS
Dec 10, 2004
58
0
0
US
I'm using the statement below to create the primary key on a table. The key needs to be non modifiable. I can't see anyway to include that restriction with this statement. Would it be more appropriate to use a create unique index statement instead?

ALTER TABLE adspxapi in Dictionary ADD PRIMARY KEY (AdNumber,EntryYear,PubNumber) #


Jim R
 
Looking at the docs, I would suggest issuing the CREATE INDEX with the "Not Modifiable" keyword and then the ALTER TABLE to set it as a primary key. Here's the example from the docs:

CREATE TABLE t1 (c1 INT NOT NULL, c2 CHAR(10) NOT NULL)
CREATE UNIQUE INDEX t1_c1c2 ON t1(c1,c2)
ALTER TABLE t1 ADD PRIMARY KEY(c1, c2)

Also:
Before adding the primary key, you must ensure that the columns in the primary key column list are defined as NOT NULL. A primary key is a unique index and can be created only on not nullable columns.

Mirtheil
Certified Pervasive Developer
Certified Pervasive Technician
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top