Adding a Primary Key

  • 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

  • PK's are added to the table structure itself. What you are showing is a select statement, where a PK can not be defined.

    I think you want to use ALTER TABLE (See BOL for proper syntax) to add the PK to the table itself.

    Jim Murphy
    http://www.sqlwatchmen.com
    @SQLMurph

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply