#6 Create database and table in phpMyAdmin

We can create databases and tables in the phpMyAdmin section of XAMPP. phpMyAdmin is a free software tool written in PHP. It is used to handle the several operations of MariaDB and MySQL. Operations like managing databases, tables, relations, indexes, users, etc can be performed using User Interface or we can use the console to write the SQL queries.

Click on new which is on the top-left side to create a new database.

Write your desired database name, you can select encoding from the dropdown which is in front of the input box, and click on create to create the database.

Your database is created successfully. You can see the name of the created database on the left bar. Now it will ask you to create a table with the number of columns. The table name is the entity you want to represent using the data like a student, employee, etc. Columns are the attributes of the entity, for example, if the table is a student then its columns can be student roll number, name, address, etc. Here we are creating the table to store the data employees so table name will be employe and columns will be Id, Name, Mobile number. After entering the table name and columns click on the Go button.

In the above step, we have defined the table name and columns. Now, we have to name those columns and we need to define the type of data they can hold. Now, we have 3 rows to defines the column names. The first column will hold Employee ID and the type of that column will be INT means it will accept the integer numbers only. Length/Values is a property that will let us define the range of Id. We can save a number having 10 digits in it.

The next property is Default, which will let us define the default value for that column. If we select the As defined then we need to provide the value and every time we enter any new record then that value will be taken.

The collation property is used to set the encoding type and other types. You can select any utf-8 type.

Attributes property is used to set the general attributes for a particular column. Binary is used when the entered data will be of two types i.e. yes or no. For example, if the employee is present or not to define that we can use this property.

The next property is null if you select the checkbox then this column can take null values. After that next property is Index it is also known as Key, Here I will select the Primary because the Employee ID is our primary key, and if you define any column as Primary then that column can not be null and it should be unique. After selecting Index as primary you will get a pop-up, just click on Go. After Index, the next Property is A_I i.e. Auto Increment. If we check this checkbox then the values will be set automatically and each time value will get incremented by one.

The next property is Comments, we can add any text here to describe our column, Virtuallity is a new property that has two values VIRTUAL and STORED. If we select VIRTUAL then the values are not stored they will be evaluated when the rows are read, if we select STORED then the values get evaluated and stored when the rows are inserted or updated. Next is Move columns which basically helps to adjust our columns position. After that comes Media type, we can set the type of data this column will hold. For name, address we can select text/plain. The next properties are for the media type only but they are more specific.

I have added two more columns for Employee name and Employee Mobile Number. For Name, I have selected type as VARCHAR, which defines that our values will be plain text. And for Mobile Number I have selected Type as BIGINT because the Mobile Number has a larger range, also I have selected Index as UNIQUE which means our values should be unique. After adding the data you can click on Save to create a table.

After creating the table, keep the table selected using the left bar and navigate to the Structure tab. You will get to see the structure of our selected table and you can edit that structure if you want.

Now, we will try to add one record to our created table. Go to the Insert tab and fill in the details like shown below and click on Go. Keep the Value field of empId empty because it will be automatically generated.

Here as you can see we got the message as 1 row inserted. Also got the query to add the data if you want you can change the previous values and click on the Go button which is at the bottom.

So here is that one inserted record with auto-generated ID and name and mobile number which we provided.

Leave a Comment

Your email address will not be published. Required fields are marked *