Primary Key AutoNumber Field

M

MGFoster

a said:
How can I create Primary Key autonumber field by SQL Command?
For existing data start from 1 and end at the end of rows
Example:
Field Name : Id Auto Number (Primary Key)
Id Name
1 a
2 b
3 c
and so on
thank you

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

If you have an existing table (TableA), like this:

ALTER TABLE TableA ADD COLUMN Id COUNTER PRIMARY KEY;

If you don't have the table, like this:

CREATE TABLE TableA (
Id COUNTER PRIMARY KEY,
Name, Text(1) NOT NULL
);

In the JET db (Access) the "Counter" data type is the AutoNumber data
type. If you are using SQL Server as your back-end, substitute
IDENTITY(1,1) for COUNTER.

You can run both DDL statements from the SQL view of a QueryDef.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
** Respond only to this newsgroup. I DO NOT respond to emails **

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

iQA/AwUBR9jNRoechKqOuFEgEQKW5QCg0KES8v0nCOwsmqMzPDUC5Ii4ryAAn2Oy
f/Nq7qajlYDhxg6F714MqX+W
=pRK3
-----END PGP SIGNATURE-----
 
A

a

How can I create Primary Key autonumber field by SQL Command?
For existing data start from 1 and end at the end of rows
Example:
Field Name : Id Auto Number (Primary Key)
Id Name
1 a
2 b
3 c
and so on
thank you
 

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

Top