In previous chapter, we have learned how to create database using mysql interface. In this chapter, we are going to learn how to create table using MySQL interface.
If you remember, in previous when you have created the database, it asked to create table. Lets proceed.
We are going to create following table in MySQL.
This table has four columns, five records.
If you are not aware of the difference between database and table, then read following article.
Create Table in MySQL using MySQL Interface
Identify column names:
In the above table. The column names are Roll_no, Student_name, Subject and Marks.
Idetify each column data type.
From the above table:
- Roll_no is INT datatype
- Student_name is VARCHAR datatype
- Subject is VARCHAR datatype
- Marks is INT datatype
If you are not aware of MySQL datatypes then read following article:
Estimate each column data value length
In the above table:
Roll_no value cant be larger than 100 (lets assume 80 students are there)
Therefore the length of Roll_no value can not be more than 3
Similarly, we are storing first name of students. So the length of student name value wont be greater than 50
Similarly subject value is math which is always going to be same because the table is about math marks. Therefore the length of subject value wont be greater than 4.
Similarly, maximum number on can secure in maths is 100. Therefore, the maximum length of marks value wont be greater than 3.
Start xampp. (If you have already started xampp, ignore step 4)
If you are not aware of xampp, and how to install it, then read following article.
Visit following url:
If using windows: http://localhost/phpmyadmin/
If using mac: http://localhost:8080/phpmyadmin/
A following similar page going to appear
Look through left column and then click on your database. I am going to use gyanol_db (which I have created previously)
Then following screen appears.
Provide a table name. You can provide any name. But no space and special characters are allowed. To use multiple names use under score. I am going to provide table name – ‘student_name’
By default it is showing number of columns 4. You can change the number as per your need. But in our example, we have four columns. So we are leaving it as it is. Then click on go.
Then following screen going to appear.
First of all, we are not required to provide information in all the input fields. But to create table, we are required to provide minimum, column name, data type, and length. Thats it.
In step 02 and Step 03 we have identified column name, column data type, and its length. Now enter into the table interface as above. Then click save.
Congratulations, you have just created one table for database successfully.
NOTE: The created table is blank as we have only created the table but has not provided any values yet.
In next chapter we are going to learn, how to insert data value in to the table using mysql interface.