In this guide, you are going to get helpful information about how to create a table in SQL. You know that SQL controls only RDBMS programs and the RDBMS program stores the data in table format in the database. Therefore, we need to make table/tables to store data.
In the previous posts, You have gotten an intro to SQL.
Before creating a table, your first step is to create a database.
And make sure, the database is selected in which you are going to create tables. To do that, click on the database you want to be created a table in, and then click on SQL to open the editor.
Otherwise (When a database is not selected.), it will show you an error like this: #1046 - No database selected.
A table consists of columns.
So, write a query for creating a table that will be
CREATE TABLE users();. The columns are also made up while creating a table, so in the parenthesis (after the table name), write code for the columns.
Each column will contain data like numbers & string so we have to also define the column's data type.
Basically, INT data type is defined for numbers means if you are going to store the number in that particular column then set its data-type to INT (Integer).
And the VARCHAR data type is defined for strings. Words are known as strings in the respect of programming.
The maximum capacity for storing integer digits in the column, in which data-type is INT can not exceed 255 digits. And, the minimum digits can be 0.
Each column is separated by a comma except the last column. See the example below.
Thus, the final code to make a table containing columns with its data type will be-
CREATE TABLE users(name VARCHAR(25), email_id VARCHAR(50), mobile_no INT(15));
Easy to understand code:
CREATE TABLE users( name VARCHAR(25), email_id VARCHAR(50), mobile_no INT(15) );
Your table has been created to see it click on the table name from the left panel.
You will see it is empty because we have not inserted any data into it. Learn how to insert data in a table.