• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Sql » Tutorials » SQL CREATE TABLE Statement
Next →
← Prev

SQL CREATE TABLE Statement

By Dinesh Thakur

The create table statement is used to create a new table. The CREATE TABLE statement defines a table. The definition must include its name and the names and attributes of its columns. The definition can include other attributes of the table, such as its primary key or check constraints. This statement comes under the DDL statement.

Syntax:
 
SQL> Create table tablename 
(Column1 data type [default exp] [Constraint],
 Column2 data type [default exp] [Constraint], 
Column3 data type [default exp] [Constraint], 
); 

To create a new table, enter the keywords create table followed by the table name, followed by an open parenthesis, followed by the first column name, followed by the data type for that column, followed by any optional constraints, and followed by a closing parenthesis. It is important to make sure you use an open parenthesis before the beginning table and a closing parenthesis after the end of the last column definition. Make sure you separate each column definition with a comma. All SQL statements should end with a”;”.

Example:
 
SQL> Create table employee 
(Name varchar2 (15), 
Eid number (6), 
Age number (3), 
City varchar2 (30), 
State varchar2 (20)); 
Table created.   

If you want to see the structure of the table then use the following command on SQL prompt.

SQL > DESC employee; 

As you can see that this command displays the entire attribute names with their data type and if constraints are imposed then their detail also.

You can also create a table from an existing table by copying the existing table’s columns. It is important to note that when creating a table in this way, the new table will be populated with the records from the existing table (based on the SELECT Statement).

Syntax #1 - Copying all columns from another table
 
 SQL>CREATE TABLE new _table AS (SELECT * FROM old_table);
 
Example:
 
SQL> CREATE TABLE persons AS (select * from persons);
 
Table created. 

This would create a new table called persons that included all columns from the persons table.

If there were records in the old table, then the new table would also contain the records selected by the SELECT statement.

Syntax #2 – Copying Selected columns from another table

SQL>Create Table Tablename (<columnname1> columnname2>) as select Statement;

Where <columnnamel>, columnname2> are the new columns in new table with new name to be associated with the values returned by the subquery.

Example: SQL> Create Table Persons (Person_id, name) AS SELECT (P_Id, FirstName) from persons;

Table created.

Note: Creating a table from another table without copying any values from the old table:

Example:

SQL> CREATE TABLE persons AS (select * from persons where I=2);
 
Table created. 

We’ll be covering the following topics in this tutorial:

  • Modifying the Table Structure with alter Table Command
  • Anytime you want to change the definition of an SQL table. You could:

Modifying the Table Structure with alter Table Command

After creating the table one may have need to change the table either by adding new columns or by modifying tile existing columns. The SQL ALTER TABLE statement is the SQL command that makes changes to the definition of an SQL table. Table structure can be changed by using alter command. With this command Field type or property can be changed or a new field can be added. This sql alter table command is used like create table command. To alter a table, the table must be in your schema, or you must have alter table privilege.

Anytime you want to change the definition of an SQL table. You could:

• Add a column to a table.

• Change the definition of an existing column in a table.

• Drop a column from a table.

• To enable or disable integrity constraint.

• If need specify the default value for the existing columns.

 

You’ll also like:

  1. SQL CREATE INDEX Statement and Types of Indexes
  2. SQL ALTER TABLE Statement
  3. SQL DROP TABLE Statement
  4. SQL DELETE Statement
  5. SQL SELECT INTO Statement
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

SQL Tutorials

SQL Tutorials

  • SQL - Home
  • SQL - Select
  • SQL - Create
  • SQL - View
  • SQL - Sub Queries
  • SQL - Update
  • SQL - Delete
  • SQL - Order By
  • SQL - Select Distinct
  • SQL - Group By
  • SQL - Where Clause
  • SQL - Select Into
  • SQL - Insert Into
  • SQL - Sequence
  • SQL - Constraints
  • SQL - Alter
  • SQL - Date
  • SQL - Foreign Key
  • SQL - Like Operator
  • SQL - CHECK Constraint
  • SQL - Exists Operator
  • SQL - Drop Table
  • SQL - Alias Syntax
  • SQL - Primary Key
  • SQL - Not Null
  • SQL - Union Operator
  • SQL - Unique Constraint
  • SQL - Between Operator
  • SQL - Having Clause
  • SQL - Isnull() Function
  • SQL - IN Operator
  • SQL - Default Constraint
  • SQL - Minus Operator
  • SQL - Intersect Operator
  • SQL - Triggers
  • SQL - Cursors

Advanced SQL

  • SQL - Joins
  • SQL - Index
  • SQL - Self Join
  • SQL - Outer Join
  • SQL - Join Types
  • SQL - Cross Join
  • SQL - Left Outer Join
  • SQL - Right Join
  • SQL - Drop Index
  • SQL - Inner Join
  • SQL - Datediff() Function
  • SQL - NVL Function
  • SQL - Decode Function
  • SQL - Datepart() Function
  • SQL - Count Function
  • SQL - Getdate() Function
  • SQL - Cast() Function
  • SQL - Round() Function

Other Links

  • SQL - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW