CREATE TABLE statement is used to create a table in database. This statement creates a table with the specified column and datatypes.
Syntax:
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... columnN datatype );
Example: The following SQL query creates a table STUDENT
in the database with four attributes (columns): STU_ID
to store student id, STU_NAME
to store student name, AGE
to store student’s age and ADDRESS
to store student’s address. You can also specify the primary key while creating a table, this is optional.
CREATE TABLE STUDENT ( STU_ID INT NOT NULL, STU_NAME VARCHAR (30) NOT NULL, AGE INT NOT NULL, ADDRESS VARCHAR2 (50), PRIMARY KEY (STU_ID) );
After inserting few rows in this newly created table, it will look like this:
STU_ID | STU_NAME | AGE | ADDRESS |
---|---|---|---|
1001 | Chaitanya | 35 | Noida |
1002 | Ajeet | 34 | Delhi |
1003 | Steve | 28 | Chennai |
1004 | Ram | 40 | Agra |
1005 | Rick | 36 | Patna |
Leave a Reply