Primary Key AutoNumber Field

  • Follow


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 


0
Reply a 3/13/2008 4:44:23 PM

a wrote:
> 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-----
0
Reply MGFoster 3/13/2008 6:44:29 AM


1 Replies
554 Views

(page loaded in 0.053 seconds)


Reply: