If you just created the new database intsql click on that name on the left of PHPMyAdmin now. If you could not create it click on the name of the database you do have.
If you do not have the power to create databases you can end up with a lot of tables and sometimes too many to remember. You might also have two sites which use tables which you want to have the same name but you can't. To help with this problem name tables to keep related tables organised. Instead of using a name like product for example use the name intsql_product. That way all the related tables will be sorted together on the left of PHPMyAdmin and it is also much less likely that you will accidentally use the wrong table.
If you have not been able to create a new database add the bit before the underscore to all table names from now on.
Even if you are able to create databases there is a very good argument for using this naming method because that allows you to later on move or copy the tables to another database server where you are not able to create new databases.
Creating the tables
If you just created a new database you will be told there are no tables and you should see a form ready to create one as shown in the screen shot. If you already have tables they will be listed and below them is the form to create new ones.
Put the name firsttable in that form field and make the number of columns 5. Press the Go button. You now have a form to fill in but before you do look towards the bottom for a drop down labelled Storage Engine. This is the choice of code/program which will run the database for you. If it is not InnoDB change it to that. InnoDB can handle some things we will use later. If you cannot choose InnoDB then you might need to look for a different server or contact the hosting company and ask why it is missing.
The form you have to fill in has a number of entries repeated five times:
- the name of the field
- the type of data (numbers, text etc.)
- the length or size limit for that data
- if you want a default bit of data to be put in you choose it next
- you can set the collation different for a field if it will hold a different type of language
- of the attributes only one is used a lot (unsigned for numeric data which cannot be negative)
The rest you can ignore for now and may be very different on different versions of PHPMyAdmin.
Creating the first table
In the five rows fill in this data to the Name, Type and Length/Values fields leaving the rest blank for now:
- cdReference, INT (leave Length empty)
- cdTitle, VARCHAR, 50
- cdArtist, VARCHAR, 50
- cdPrice, DECIMAL, 10,2
- cdLabel, VARCHAR, 25
Do not press the Save button yet. You will be adding some more to it but first check that you understand what you have done so far. You already met INT and VARCHAR. DECIMAL is any number with a decimal point and the second value is how many numbers to allow after the decimal point.
Some more things to add to the table (primary keys will be explained soon):
- the first field is a reference number unique to each CD which will be held in this table and none of those can be negative so in the Attribute drop down for this field choose UNSIGNED
- also for that field choose PRIMARY under Index (if you get a pop up just press Go)
- as this field is the primary index which must always be unique put a tick under A_I (auto-increment automatically inserts a unique number any time you create a new item in the table and is very useful)
- make cdPrice UNSIGNED as well because a CD could not have a negative price
- leave comments, collation and PARTITION definition empty
Now Save and you will be taken to a view of your first table.