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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Temporary Constraint, Object

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 KEYWORD
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 #t
DROP TABLE #x
GO




--THIS IS OK
CREATE TABLE #t (
SaleID INT,
SaleID2 INT
PRIMARY KEY (SaleID, SaleID2)
)


CREATE TABLE #x (
SaleID INT),
SaleID2 INT
PRIMARY KEY (SaleID, SaleID2)
)


DROP TABLE #t
DROP TABLE #x
GO




It 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 t
DROP TABLE x
GO

The common standard to use for naming the primary key constraint name is PK_TableName. So it would be PK_t and PK_x.

Tara
Go to Top of Page
   

- Advertisement -