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
 General SQL Server Forums
 New to SQL Server Programming
 How to create two identity in One TABLE ?

Author  Topic 

cecilvcj
Starting Member

1 Post

Posted - 2011-05-25 : 08:19:27
Hi,
I'm new bee to SQL.
plz help to create.
How to create two identity in One TABLE ?



cecil vcj

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-05-25 : 08:36:45
You can't. There can only be one identity column in a table.

Why do you want two?

--
Gail Shaw
SQL Server MVP
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-05-25 : 21:36:04
IDENTITY is the count of PHYSICAL insertion attempts (not successes) to a table. It is also not a column; it is a table property. Logically, you can only have one. A good SQL programmer will never use it because it is not part of a LOGICAL database design.

--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-05-26 : 06:45:34
Guess I'm not a good SQL programmer then...

Like everything, it has it's place and can be used well or misused terribly.

--
Gail Shaw
SQL Server MVP
Go to Top of Page

jfarrugia
Yak Posting Veteran

55 Posts

Posted - 2011-05-26 : 06:47:15
if you mean having two columns as identity you can use a composite type p.k.. just select two columns, right click, set as p.k

Where software development knowledge meets the reader
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-05-26 : 07:33:18
You can create an identity then use a computed column or view to emulate another one based on it.
Why you would want to do this is another question (and you probably wouldn't).

As to PK - and identity and PK are different things. A composite PK is something different to two identities also. Not really connected at all.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

jfarrugia
Yak Posting Veteran

55 Posts

Posted - 2011-05-26 : 08:14:29
yes you can have an identity column which is not a p.k.. however i assume that cecilvcj was referring to p.ks? if not, my bad.

Where software development knowledge meets the reader
Go to Top of Page

Bazalddo
Starting Member

22 Posts

Posted - 2011-05-26 : 08:49:47
Cecil,

I think it would be much easier for people to help you if you gave us the reason why you need two identity columns....

Baz

Shahbaz Ahdi
Apps Developer
ODEON/UCI Cinema
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2011-05-26 : 12:39:27
You can't do it now, but there is a SEQUENCE feature in the upcoming Denali release of SQL Server:
http://sql-articles.com/articles/general/sequence-feature-in-denali/





CODO ERGO SUM
Go to Top of Page
   

- Advertisement -