Now that you know what a SQL table looks like, and you have the tools to start running SQL commands, let’s go ahead and create one. If you have installed Xampp, go ahead and go to http://localhost in your browser, click on phpmyadmin.

Next need to create a database

In the text box under the create new database, enter actors as the name of the database and click ‘create’

Now go to the tab on top where it says SQL and click that. From now on we will always go to this tab to run our commands. phpmyadmin does have a gui interface to create, edit, and delete databases, but our goal is to learn SQL so we will go the way of the code.

Okay, so with the SQL tab open we are going to run our first query:

Type in:

CREATE TABLE names
(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
name VARCHAR( 100 )
);

(notice the commands are in all capitals, it is not required but it makes a clear distinction between SQL syntax and column names)

Let’s look at that for a moment,

  • id is going to be the unique identifier for each value
  • NOT NULL means it won’t show a null value
  • AUTO_INCREMENT means the id number will automatically increase by each row added
  • PRIMARY KEY is the unique identifier for each value- no two rows can have the same primary key

For the name column we used VARCHAR or variable character field meaning we could basically put anything in there and is the most widely used field. the 100 is the maximum number of characters allowed so if someone’s name is longer than that you would probably get an error…but I don’t know anyone who’s name is longer than 100 characters, do you? :)