Before that, you need to create a database.
Create, rename, drop, database table
Create a table
To create a table using SQL you have to use the CREATE TABLE statement.
Basic syntax
CREATE TABLE Table_name
(
Column1_name data_type (size),
Column1_name data_type (size),
Column2_name data_type (size),
Column3_name data_type (size),
………………………………………………
ColumnN_name data_type (size)
);
Here is each column's syntax. Remember that, we will not give a comma after the syntax for the last column.
Create a table using SQL example
Create this table using SQL (standardized query language). You have a database name company. You need to create a table under this database name "Job".
Job
E_id | Name | Gender | Age | City | CGPA |
Keep E_id size in 5 digits, Name 18 digits, Gender 15 digits, Age 5 digits, City 15 digits, CGPA 3 digits and take 2 digits after the decimal point.
Always select a key as the primary key
Solution:
For doing this open Xampp. And then write SQL syntax like this.
Here we are keeping E_id as the primary key.
CREATE TABLE Job
(
E_id int (5),
Name varchar (18),
Gender varchar (15),
Age int (5),
City varchar (15),
CGPA double (3, 2),
PRIMARY KEY (E_id)
);

Clicking on the go button Job table will be created under the company database. If you want to view the table, just click on Structure.

Rename table
To rename the table name in SQL you need to write a command like this-
RENAME Present_name_of_the_table TO New_name;
Rename table name in SQL example
Rename the table from Job to New_Job.

RENAME TABLE Job TO New_Job;

Drop table(Delete table)
Before deleting a table under a database at first click on that database. To drop table in SQL write syntax like thisDROP TABLE Table_name;
If you want to drop the New_Job table (Table already renamed) then write syntax like this. New_Job table is under the company database.
DROP TABLE New_Job;
Now know how to insert records into the created table in the database.
0 Comments