www.pickatutorial.com Computer Tutorials
Top Tutorials: C/C++ | C#.NET | PHP MySQL | Java | Java Script | jQuery | HTML | xHTML | HTML5 | VB Script| CSS
Lessons MySQL Primary Keys Bookmark and Share
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Lesson 9
Lesson 10
Lesson 11
Lesson 12
Lesson 13
Lesson 14
Lesson 15
Lesson 16
Lesson 17
Lesson 18
Lesson 19
Lesson 20
Lesson 21
Lesson 22
Lesson 23
Lesson 24
Lesson 25
Lesson 26
Lesson 27
Lesson 28
Lesson 29
Lesson 30
Lesson 31
Lesson 32
Lesson 33
Lesson 34
Lesson 35
Lesson 36
Lesson 37
Lesson 38
Lesson 39
Lesson 40
Lesson 41
Lesson 42
Lesson 43
Lesson 44
Primary Keys and Auto Increment Fields
This is true for al most all of the relational database management systems that each table of the database has to have a primary key field. A primary key field is used to uniquely identify the rows or records in a table. Each primary key value must be unique within the table. Furthermore, the primary key field cannot be null because the database engine requires a value to locate the record.

Often the primary key field is some sort of a number e.g. ID, and is often used with the AUTO_INCREMENT setting. When we use AUTO_INCREMENT with primary key, or any other field, it means that the value of the field is to be incremented automatically, usually by 1 each time a new record is added.

To ensure that the primary key field is not to be null, we must add the NOT NULL setting to the field.

The following SQL code sets the studentID field as the primary key field.

$sql = "CREATE TABLE Students
      studentID int NOT NULL AUTO_INCREMENT,
      PRIMARY KEY(studentID),
      FirstName varchar(15),
      LastName varchar(15),      
	  Age int

Home - Advertise - Contact - Disclaimer - About Us
© Since 2006 pickatutorial.com -- All Rights Reserved.