PHP MySQL Create and Drop Tables (Cont.)
Each table should have a primary key field, which is used to uniquely identify the rows in a table.
The primary key field cannot be null because the database engine requires a value to locate the record.
The following example creates, populates, and selects a table Papers
by using the SQL commands:
CREATE TABLE Papers (
paperID INT NOT NULL AUTO_INCREMENT,
title VARCHAR(32) NOT NULL,
PRIMARY KEY( paperID ) );
INSERT INTO Papers( title ) VALUES( '$title' );
SELECT * FROM Papers;
|
The primary key field is often an ID number, and is often used with the
AUTO_INCREMENT
setting.
AUTO_INCREMENT
automatically increases the value of the field by 1 each time a new record is added.