Jump to content

Archived

This topic is now archived and is closed to further replies.

gardan06

getting an auto_incremented integer..

Recommended Posts

if you set your primary key as auto_incremented and you have a query "insert into table values('','{$var2}'...)", how can you save the newly saved primary key as a variable?

Share this post


Link to post
Share on other sites
I know this thread is probably old, but I need help with Auto Increment.

This is the table I have created with auto_increment:


CREATE TABLE appointment(appointment_id MEDIUMINT NOT NULL AUTO_INCREMENT, Primary Key (appointment_id), student_id varchar(8), INDEX (student_id), FOREIGN KEY (student_id) REFERENCES student(student_id), lecturer_name varchar(50), INDEX (lecturer_name), FOREIGN KEY (lecturer_name) REFERENCES lecturer(lecturer_name), appointment_date DATE, appointment_time TIME) TYPE=INNODB;

Is the auto increment value also set as a primary key through Primary Key (appointment_id) or does it overide the primary key and its rules?

Share this post


Link to post
Share on other sites
auto increment and primary key are compatible and often used together so you don't have to manually increment the primary key.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.