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 |
|
skillile
Posting Yak Master
208 Posts |
Posted - 2003-12-12 : 15:45:27
|
| Any definition on this would help. A #temporary table is unique to a users session. I thought the objects were unique to the #table.--FIRST EXAMPLE FAILS WITH CONSTRAINT KEYWORDCREATE TABLE #t ( SaleID INT, SaleID2 INT CONSTRAINT cname PRIMARY KEY (SaleID, SaleID2))CREATE TABLE #x ( SaleID INT, SaleID2 INT CONSTRAINT cname PRIMARY KEY (SaleID, SaleID2))DROP TABLE #tDROP TABLE #xGO--THIS IS OKCREATE TABLE #t ( SaleID INT, SaleID2 INT PRIMARY KEY (SaleID, SaleID2))CREATE TABLE #x ( SaleID INT), SaleID2 INT PRIMARY KEY (SaleID, SaleID2))DROP TABLE #tDROP TABLE #xGOIt seems the cname Constraint is actually created and its own object outside the table, is this correct??. I don't really have a questions but just curious for a definition as if this is true.Thanks |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-12-12 : 15:52:32
|
| This isn't just for temporary tables. You can't have duplicate constraint names regardless if they are on different tables. Change your example to this and you'll see:CREATE TABLE t (SaleID INT,SaleID2 INT CONSTRAINT cname PRIMARY KEY (SaleID, SaleID2))CREATE TABLE x (SaleID INT,SaleID2 INT CONSTRAINT cname PRIMARY KEY (SaleID, SaleID2))DROP TABLE tDROP TABLE xGOThe common standard to use for naming the primary key constraint name is PK_TableName. So it would be PK_t and PK_x.Tara |
 |
|
|
|
|
|
|
|