List:General Discussion« Previous MessageNext Message »
From:Andrey Subbotin Date:December 10 2003 10:27am
Subject:Re: MySQL -- Sequences -- Do they exist
View as plain text  
Hello noel.
Wednesday, December 10, 2003, 5:09:30 PM, you wrote:

nkmdi> If not is there anyway to automatically generate primary keys for
nkmdi> tables in MySQL.

CREATE TABLE ttt (
       id int not null auto_increment primary key,
       name varchar(100) not null
);

Please note "auto_increment" token in the example above. It tells MySQL
that id is an auto-incrementing primary key for the table. So, to
insert a row you'd just issue the following query:

INSERT INTO ttt (name) VALUES ('some name here');
INSERT INTO ttt (name) VALUES ('another name here');

or

INSERT INTO ttt (id, name) VALUES (NULL, 'some name here');
INSERT INTO ttt (id, name) VALUES (NULL 'another name here');

Anyway, you'll get the following two records after that:

1, 'some name here'
2, 'another name here'

I hope that helps.

-- 
See you,
Andrey.

[ subbotin@stripped | ICQ# 114087545 | 2:5090/114@stripped ]

...Perfect guest: One who makes his host feel at home.
Attachment: [application/pgp-signature]
Attachment: [application/pgp-signature]
Thread
MySQL -- Sequences -- Do they existnoel.king210 Dec
  • Re: MySQL -- Sequences -- Do they existMartijn Tonies10 Dec
  • Re: MySQL -- Sequences -- Do they existVictoria Reznichenko10 Dec
  • Re: MySQL -- Sequences -- Do they existAndrey Subbotin10 Dec