SQL Create Table

sql create table
SQL Create Table
CREATE TABLE– Using create table we can create empty table in oracle database.
 
 

SQL create table syntax.

 

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 in sql oracle 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 after create table in oracle 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.
 
SQL> select *from customer where cust_id=100;
 
 
 

Useful Post:-

Leave a Comment