Create, rename, drop, database table using SQL. To Create a table, rename the table and drop the table at first you need to create a table.

Before that, you need to create a database.

Create, rename, drop, database table

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)
);

Create a table


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. 

Create table, rename table, drop table

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.

Solution

Rename table


RENAME  TABLE Job TO New_Job;


Now click on go, the table will be renamed. If you see it is not renaming then reload the page. 


Create table, rename table, drop table

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 this

DROP 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;


Drop table


Click on go. By this, the table New_Job under the company has been deleted.
Now know how to insert records into the created table in the database.