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
 Database Design and Application Architecture
 is there unique identity for record??

Author  Topic 

azaade
Starting Member

3 Posts

Posted - 2011-03-28 : 02:49:11
Hello
Well hope someone here can help me.. I want to know is there an unique identity for row in the structure of SQL which not shown in sql but it is exist that when we create a record sql made it for itself.

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-03-28 : 04:37:35
Kinda, but it's not one that's accessible or constant.

Why?

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

azaade
Starting Member

3 Posts

Posted - 2011-03-29 : 01:07:50
thanks dear GilaMonster,
i should add that we have no primary key in our table, And we try not to add duplicate row to our database.. i need that identity in these cases
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-03-29 : 02:02:48
Nope, wrong approach. If you want something to prevent duplicates, put a unique constraint or primary key on the set of rows that you want to be unique.

That 'identity' wouldn't help prevent duplications anyway, it's always unique, so you could insert 10 identical rows.

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

azaade
Starting Member

3 Posts

Posted - 2011-03-29 : 03:04:10
hmm, why wouldn't help? it can be like as primary key, and if it saw the values of row is duplicate, it can give us an error. don't you think so?
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-03-29 : 05:22:56
No I don't think so.

A primary key doesn't check if the rest of the row is a duplicate, it checks if IT is duplicate. If you have a meaningless primary key the entire rest of the row can be duplicated and that's not an error

If you need some portion of the row to be unique, define a unique constraint or primary key on that set of columns. Adding a meaningless column as primary key (which you can do with an int identity, no hidden features required) just means you'll get duplicate rows with different meaningless pk values.

And maybe do some reading on database design too?

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

- Advertisement -