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.
Author |
Topic |
azaade
Starting Member
3 Posts |
Posted - 2011-03-28 : 02:49:11
|
HelloWell 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 ShawSQL Server MVP |
|
|
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 |
|
|
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 ShawSQL Server MVP |
|
|
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? |
|
|
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 errorIf 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 ShawSQL Server MVP |
|
|
|
|
|
|
|