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 |
sql_2k
Starting Member
26 Posts |
Posted - 2008-03-05 : 05:16:42
|
Hi, Is there any datatype that cann't be used for Primary key column in a DB table. |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-05 : 05:20:48
|
TEXT, NTEXT and IMAGE.Try for yourself.DECLARE @Sample TABLE ( MyColumn TEXT PRIMARY KEY -- Change datatype and try! ) E 12°55'05.25"N 56°04'39.16" |
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-05 : 05:33:55
|
of course there's a difference between what CAN'T be used and what SHOULDN'T be used what did you have in mind?Em |
 |
|
sql_2k
Starting Member
26 Posts |
Posted - 2008-03-05 : 05:54:08
|
I would appreciate if you also let me know what datatype shouldn't be used for primary -key column.quote: Originally posted by elancaster of course there's a difference between what CAN'T be used and what SHOULDN'T be used what did you have in mind?Em
|
 |
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-03-05 : 06:00:52
|
it really depends on your requirement as to what makes a good / bad primary key.there's nothing really stopping you making a 'bit' column a primary key for example, but would you really want to? or varchar(8000) for example?Em |
 |
|
Jeff Moden
Aged Yak Warrior
652 Posts |
Posted - 2008-03-05 : 23:00:02
|
VARCHAR(8000) would make a really bad primay key ... ;-)--Jeff Moden |
 |
|
sql_2k
Starting Member
26 Posts |
Posted - 2008-03-06 : 03:24:13
|
This is true, It depends on requirement to decide a good primary key.What I wanted to know - In DB table we have a coulmn of varchar(10) type which should be unique. But for easy handling I have added another identity primary key column to the table. So what I wanted to understand, as the varchar column uniquely identifies, so shall we go for making it as p-key or is it advisable to uphold another coulmn of int/identity type as primary key.quote: Originally posted by Jeff Moden VARCHAR(8000) would make a really bad primay key ... ;-)--Jeff Moden
|
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-03-06 : 03:49:40
|
You can only have one primary key on a table.But you can have several UNIQUE constraints or indexes on a table. E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|