Click to See Complete Forum and Search --> : add a primary key
aaryan
November 15th, 2006, 06:13 AM
hi guys,
i have created a table say t1 with columns c1(int) and c2(varchar). now what if i want to make the column c1 a primary key!!!??? the alter commands shows error.
davide++
November 15th, 2006, 06:33 AM
hi guys,
i have created a table say t1 with columns c1(int) and c2(varchar). now what if i want to make the column c1 a primary key!!!??? the alter commands shows error.
Well...
If you post message error and say that database you're using, someone will help you in the best way.
I'm sure of this.
aaryan
November 16th, 2006, 12:06 AM
i am sorry for not mentioning the db, it's sql server 2000. if i try to add the primary key to the existing column (thro sql analyzer) by alter -add commands, it shows the column already exists. i don't know how to write the exact query for adding the key to the already existing column in the db.
hope i am clear this time.
davide++
November 16th, 2006, 04:20 AM
OK :)
I don't know SqlServer, but I hope that it accepts the standard SQL syntax.
So, try a command like this:
ALTER TABLE TIPI_ATTIVITA
ADD CONSTRAINT TIPI_ATTIVITA_PK PRIMARY KEY (TIPO_ATTIVITA_ID)
where TIPI_ATTIVITA is the table name, TIPI_ATTIVITA_PK is the constraint name, and TIPO_ATTIVITA_ID is the column where you'll create the primary key (I've used Italian names for database objects to uderline the key words of the statement).
I hope this will help you.
aaryan
November 28th, 2006, 06:50 AM
thank you man.
it was so easy and i cdn't do it. anyway thankyou once again.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.