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)
 GETDATE value as primary key

Author  Topic 

SamC
White Water Yakist

3467 Posts

Posted - 2003-08-14 : 18:57:34
I've got a table of statistics with a column that's default is GETDATE

Is GETDATE resolution too coarse to be a PRIMARY KEY?

CREATE TABLE Mytable (
InsertDate AS DATETIME DEFAULT GETDATE() PRIMARY KEY
)

I'm worried that it'll run a while then hit a duplicate time on an insert. Is that possible?

Sam

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2003-08-14 : 19:05:19
See for yourself:


CREATE TABLE Mytable
(
InsertDate DATETIME NOT NULL
)

ALTER TABLE Mytable ADD
CONSTRAINT PK_InsertDate PRIMARY KEY CLUSTERED
(
InsertDate
)
GO

INSERT INTO Mytable VALUES (GETDATE())
INSERT INTO Mytable VALUES (GETDATE())
INSERT INTO Mytable VALUES (GETDATE())
INSERT INTO Mytable VALUES (GETDATE())
INSERT INTO Mytable VALUES (GETDATE())
INSERT INTO Mytable VALUES (GETDATE())

SELECT * FROM Mytable

DROP TABLE Mytable



Tara
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2003-08-14 : 19:07:39
The resolution is approxiamtely 3.33 milliseconds.

So of course it is possible. But if it is the key, what is the problem?

DavidM

"SQL-3 is an abomination.."
Go to Top of Page

SamC
White Water Yakist

3467 Posts

Posted - 2003-08-14 : 19:11:36
I guess this is a dead-end

Oh well

Sam
Go to Top of Page
   

- Advertisement -