Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

primary key and auto_increment 1

Status
Not open for further replies.

soundmind

Technical User
Jun 30, 2003
16
US
Hi,

When you create a new table and set one field as auto_increment, does this field automatically become the primary key as well?

I tried modifying a table after I created it, with not much success.

1) I tried changing an existing field to auto_increment, didn't work.

2) I tried changing an existing field to primary key, didn't work.

3) I added a new column and set auto_increment, this worked.

4) Setting column #3 as primary key caused an error.

5) I tried adding a new column as primary key, but didn't work either.

I guess I'm confused about what can be done to an existing table/column and what can't.

Help please?

Thanks!
 
primary key and auto_increment are separate issues. auto_increment is a property for a single column. Primary key is a constraint that applies to the table.

Code:
create table t(
  c1 int not null auto_increment, 
  constraint t_primary primary key(c1))
)

If the table does not have a primary key constraint it can be added by using an alter table statement.
 
in continuation to swampBoogie, auto_increment have one property of Primary Key that they are unique. was this a source of confusion ?



[ponder]
----------------
ur feedback is a very welcome desire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top