SQL equivelant of Access [AUTO-NUMBER]

SQL equivelant of Access [AUTO-NUMBER]

Post by Dan Lockwoo » Mon, 10 Jan 2000 04:00:00



Does anyone know the SQL equivelant of Access's AUTO-NUMBER function?

Thanx,
Dan

 
 
 

SQL equivelant of Access [AUTO-NUMBER]

Post by Itzik Ben-Ga » Mon, 10 Jan 2000 04:00:00


You can create a column with an auto number with the IDENTITY property,
e.g.:
CREATE TABLE MyTable(
col1 int NOT NULL IDENTITY(1,1), -- IDENTITY(seed, increment)
...)

Or you can use the IDENTITY() function that is used only in a SELECT
statement with an INTO table clause to insert an identity column into a new
table, e.g.:

SELECT IDENTITY(int, 1,1)  AS ID_Num, col1, col2...
INTO NewTable
FROM OldTable

--
BG


Quote:> Does anyone know the SQL equivelant of Access's AUTO-NUMBER function?

> Thanx,
> Dan


 
 
 

SQL equivelant of Access [AUTO-NUMBER]

Post by Neil Pik » Mon, 10 Jan 2000 04:00:00


Dan - IDENTITY

Quote:> Does anyone know the SQL equivelant of Access's AUTO-NUMBER function?

> Thanx,
> Dan

 Neil Pike MVP/MCSE.  Protech Computing Ltd
 (Please reply only to newsgroups)
 SQL FAQ (406 entries) see

 or www.ntfaq.com/sql.html (+ ntfaq download)
 or http://www.sql-server.co.uk
 
 
 

SQL equivelant of Access [AUTO-NUMBER]

Post by Itzik Ben-Ga » Mon, 10 Jan 2000 04:00:00


Books Online; think of it as your best friend. ;-)

--
BG


> Thanks!  I'm your basic beginner when it comes to the more advanced SQL
> statements.  I'm still a little unclear about the IDENTITY statement could
> you point me to a resource that may help explain it?

> Thanx again,
> Dan



> > You can create a column with an auto number with the IDENTITY property,
> > e.g.:
> > CREATE TABLE MyTable(
> > col1 int NOT NULL IDENTITY(1,1), -- IDENTITY(seed, increment)
> > ...)

> > Or you can use the IDENTITY() function that is used only in a SELECT
> > statement with an INTO table clause to insert an identity column into a
> new
> > table, e.g.:

> > SELECT IDENTITY(int, 1,1)  AS ID_Num, col1, col2...
> > INTO NewTable
> > FROM OldTable

> > --
> > BG



> > > Does anyone know the SQL equivelant of Access's AUTO-NUMBER function?

> > > Thanx,
> > > Dan

 
 
 

SQL equivelant of Access [AUTO-NUMBER]

Post by Dan Lockwoo » Mon, 10 Jan 2000 04:00:00


Thanks!  I'm your basic beginner when it comes to the more advanced SQL
statements.  I'm still a little unclear about the IDENTITY statement could
you point me to a resource that may help explain it?

Thanx again,
Dan


> You can create a column with an auto number with the IDENTITY property,
> e.g.:
> CREATE TABLE MyTable(
> col1 int NOT NULL IDENTITY(1,1), -- IDENTITY(seed, increment)
> ...)

> Or you can use the IDENTITY() function that is used only in a SELECT
> statement with an INTO table clause to insert an identity column into a
new
> table, e.g.:

> SELECT IDENTITY(int, 1,1)  AS ID_Num, col1, col2...
> INTO NewTable
> FROM OldTable

> --
> BG



> > Does anyone know the SQL equivelant of Access's AUTO-NUMBER function?

> > Thanx,
> > Dan