maqskywalker
asked on
sql server alter table command to add primary key
I'm using sql server 2008.
I read this article:
http://stackoverflow.com/questions/2626158/why-use-multiple-columns-as-primary-keys-composite-primary-key
I have this create table script
When I run this script that creates a table with two primary key columns that looks like this:
I read that on a sql server table on some other article, that you can only have one primary key, but you can have multiple columns in your primary key.
If I want to have the City column also be a primary key column.
Any know the syntax for the Alter Table command so that after I create the table with the script above I can then use the Alter Table command to then add the City column as one of the primary key columns?
I read this article:
http://stackoverflow.com/questions/2626158/why-use-multiple-columns-as-primary-keys-composite-primary-key
I have this create table script
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
)
When I run this script that creates a table with two primary key columns that looks like this:
I read that on a sql server table on some other article, that you can only have one primary key, but you can have multiple columns in your primary key.
If I want to have the City column also be a primary key column.
Any know the syntax for the Alter Table command so that after I create the table with the script above I can then use the Alter Table command to then add the City column as one of the primary key columns?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER