SQL CREATE TABLE – To Initially create empty table in database.
We all are aware that table is very important object in each and every database, so let start creating table in database. CREATE TABLE is the key word telling database to create new table in database.
Syntax:-
Create table table_name (
Column1 datatype,
Column2 datatype,
. . . . . . . .
CONSTRANTS constrant_name PRIMARY_NAME|UNIQUE|…
)
|
The column1 and column2 specify the column name of newly created table.
Datatype specify the types of column data (e.g char,varchar,integer,number,date etc).
SQL CREATE TABLE Example:-
Create table Customer(
Customer ID int,
First Name varchar(255),
Last Name varchar(255),
Address varchar(255),
City varchar(255)
);
|
Here Customer ID column is of type of integer which will hold integer data.
First Name , Last Name , Address and City column is of type of Varchar which will hold character.
Once table will create we can use desc keyword to check whether table created or not.
SQL> desc Customer;
Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTOMER_ID NUMBER(38)
FIRST_NAME VARCHAR2(255)
LAST_NAME VARCHAR2(255)
ADDRESS VARCHAR2(255)
CITY VARCHAR2(255)
|
Now we can check the table using select as below.
SQL> select *from Customer;
no rows selected
CREATE TABLE statement is also useful to copy the existing table into new table. We can use create table statement combination of select statement as below.
SQL> create table new_customer as select *from customer;
Table created.
Here we can use where clause to specify conditions as per your requirement.

No comments:
Post a Comment
Thanks for reading till end. I hope this will help you more to improve your knowledge.
Now it's your turn!
What do you think? Share your experience in the comments box and subscribe for more interesting post.