all groups > sql server new users > february 2007 >
You're in the

sql server new users

group:

Newbie question



Newbie question CyberDwarf
2/21/2007 12:00:00 AM
sql server new users: I need to set the primary key on an existing column within a table.
Can't somehow seem to get the syntax right.
I had assumed something like:- Alter Table <table name> Add Constraint
<constraint name> Primary Key <column name> <constraint rule>

but this don't work !!

Any help greatly appreciated

TIA

Steve

Re: Newbie question Jens
2/21/2007 9:00:18 AM
A sample would be:

ALTER TABLE [dbo].[Categories] ADD CONSTRAINT [PK_Categories] PRIMARY
KEY CLUSTERED
(
[CategoryID] ASC
)


HTH, Jens K. Suessmeyer.

---
http://www.sqlserver2005.de
---
Re: Newbie question Gail Erickson [MS]
2/21/2007 10:13:25 AM
[quoted text, click to view]

Hi CyberDwarf,

I would encourage you to look at the product documentation (called Books
Online) for syntax and examples. It's generally easier than experimenting
:>)

If you're using SQL Server 2000, you can download that latest version of
Books Online from
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
If you're using SQL Server 2005, you can download that latest version of
Books Online from
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx.

--
Gail Erickson [MS]
SQL Server Documentation Team
This posting is provided "AS IS" with no warranties, and confers no rights
Download the latest version of Books Online from
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx


[quoted text, click to view]

Re: Newbie question Bob Simms
2/21/2007 8:56:54 PM
[quoted text, click to view]
As well as the advice already posted, if there is data in the table, make
sure that the column has unique, non-null data in it, or the alter table
will fail.

AddThis Social Bookmark Button