PDA

View Full Version : help


Billybob54
11-29-01, 03:45 AM
how do you set a primary key to a table?

Bud
11-29-01, 04:52 PM
you can make a primary key like this:

create table table_name(
id mediumint(8) NOT NULL AUTO_INCREMENT,
users varchar(15),
primary key (id)
)

id would become the primary key.

To add a primary key to a column that already exists use the ALTER statement:

alter table table_name add primary key(id)

btw, anytime you use auto_increment the column must be not null and primary.


~bud