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
 Transact-SQL (2000)
 Adding a Primary Key

Author  Topic 

dougancil
Posting Yak Master

217 Posts

Posted - 2011-06-02 : 11:23:25
I have the following query and need to add a Primary Key to the Column of Employeenumber:


SELECT [Exceptions].Employeenumber,[Exceptions].exceptiondate, [Exceptions].starttime, [exceptions].endtime, [Exceptions].code, datediff(minute, starttime, endtime) as minutes INTO scratchpad3,
FROM Employees INNER JOIN Exceptions ON [Exceptions].EmployeeNumber = [Exceptions].Employeenumber
where [Exceptions].exceptiondate between '5/1/2011' and '5/8/2011'
GROUP BY [Exceptions].Employeenumber, [Exceptions].Exceptiondate, [Exceptions].starttime, [exceptions].endtime,
[Exceptions].code, [Exceptions].exceptiondate


but don't know the proper syntax when you're doing a "create" this way. What's the propery syntax to add a primary key this way?

Thank you,

Doug

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-06-02 : 12:03:45
alter table scratchpad3 add constraint pk_scratchpad3 primary key (Employeenumber)

Your group by should be just Employeenumber if this is a primary key though - I expect it won't work or you should change the query to fit the data.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -