Assign a Primary Key in Query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
What is the proper SQL to create a primary key within a query? I thought it
was the following.
CREATE UNIQUE INDEX Primary Key ON [Invoices]!(invoice_num) WITH PRIMARY
DISALLOW NULL

In the above case, [Invoices] is the table name and (invoice_num) is the
field that I am making primary.

Any help is appreciated.
Thanks
Rob Meiner
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In JET SQL:

CREATE INDEX PK_Invoices ON Invoices (invoice_num) WITH PRIMARY

Since you've declared "WITH PRIMARY" you don't have to indicate the
index is "UNIQUE" since all primary keys are unique by default, and, you
don't have indicate "DISALLOW NULL" since Primary keys are NOT NULL by
default.

In ANSI 92 SQL:

ALTER TABLE Invoices ADD CONSTRAINT PK_Invoices
PRIMARY KEY (invoice_num)

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQX/hqIechKqOuFEgEQK6gQCfZmHn6UlJsC0HMqZuOQOlJilCyqkAn38j
VaxamxP0GywPbbOAvFAH4uF4
=z6GE
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top