Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Express Edition and Compact Edition (2005)
 how create a field (id) that increments autom. ?

Author  Topic 

fabianus76
Posting Yak Master

191 Posts

Posted - 2005-10-01 : 19:58:59
I would like to create a field that increments automatically by 1 - to use it as an identifier for a row. This is so dammed simple but I can not find how to do it !

Thank you very much for any help.

By the way I configure SQLExpress with VS2005 and SQL Express Manager.

Thank you very much,
Regards,
Fabian

my favorit hoster is ASPnix : www.aspnix.com !

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-10-01 : 22:02:15
I don't believe they've changed the syntax on this one.

CREATE TABLE test(ident INT IDENTITY(1,1), col1 INT)

INSERT test(col1)
SELECT 1 UNION ALL
SELECT 2

SELECT ident, col1
FROM test

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 2005-10-02 : 05:48:50
Hi derrickleggettk,

thank you very much! That's what I was looking for.
Just one additional question - what is the diffrence between a "Identity-Increment" and a "Identity-Seed"?

Regards,
Fabian

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-10-02 : 11:36:39
Identity seed is where the number will start at when you create the column. In my example (IDENTITY(1,), it will start the numbers at one, which is the seed, and (,1)) increment by one which is the identity increment.

There are two functions (IDENT_SEED and IDENT_INCR) that return what the values were when you created the identity column.

Books Online has a LOT of good information like this and is included free with SQL Server. Have you been able to take a look at it yet?

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 2005-10-02 : 14:53:07
Hallo derrickleggett,

thank you for your reply.

Where do I find books on the web about sql server express? I write that there is a book included for free in sql-server express? I can not find it. Perhaps you could give me a hint to find something.

Thank you very much,
Regards,
Fabain

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-10-02 : 15:34:03
Here's a link for you:

http://www.microsoft.com/downloads/details.aspx?FamilyId=ADC75E35-7245-4038-9B8A-B8FABAEC16DA&displaylang=en

If you go to the main SQL Server website, you will also find a LOT of information you don't have to pay for. Here is that website:

http://www.microsoft.com/sql/default.mspx

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -