<== Back

Specifying a Primary Key

Lets go back to our table creation script. When we want to make something the primary key, we simply add "primary key" after the definition and before the comma like so: If we make this change to our script, and then re-run it it will make the new people table with these values. Then if we try to run it again, it will give a "duplicate entry" error.

Autogenerating your primary key

A better way to handle the primary key is to make it increment automatically, like so: This way there is no room for human error. Now we need to change the insert file so that it does not specify an id number. So we change it to look like this: This way it gives it an id all on it's own. Don't use names as a primary key, you need to use something like an autogenerating number, or a SS#

<== Back

nt command window and start a new command prompt.