codingstreets
Search
Close this search box.
sql-create-table-statement

Get Started: SQL CREATE TABLE Statement

In This Article, You Will Know About SQL Create Table Statement. 

Before moving ahead, let’s know a bit about the SQL Backup Database Statement.

Table of Contents

SQL CREATE TABLE Statement

In SQL, the CREATE TABLE statement is used to create a new table in the database.

Syntax

				
					CREATE TABLE table_name (
	Column_name1 datatype,
	Column_name2 datatype,
	Column_name3 datatype,
	Column_name4 datatype,
	…… 
);
				
			

The parameter “datatype” shows the type of datatype a column holds such as (varchar, int, Boolean, bit, etc.,).

Example: Use the CREATE TABLE statement to create a new table.

Create a new table called “Student_Information” containing Five columns – “Serial Number”, “Name”, ‘Class”, “Roll_No”, “Subject”.

				
					CREATE TABLE Student_Information (
Serial Number int,
Name char(12),
Roll_No  int,
Subject char(12)
);
				
			

The column Serial Number and Roll_No will hold numbers and the rest of the column will hold characters with a maximum limit of 12.

The empty “Student_Information” table will now look like this:

Serial Number

Name

Class

Roll_No

Subject

Create Table Using Another Table

Create a new table from an existing table by using the “CREATE TABLE” statement.

Since, we create a new table from an existing table, therefore, the new table will take the same column and value which are present in the existing table.

Syntax

				
					CREATE TABLE new_table_name AS
    SELECT column_name1, column_name2,...
    FROM existing_table_name
    WHERE ….;
				
			

Example: Create a new table “Student_Info” from an existing table.

				
					
CREATE TABLE Student_Info AS
    SELECT Serial Number, Name, Class
    FROM Student_Information;
				
			

If you find anything incorrect in the above-discussed topic and have further questions, please comment below.

Connect on:

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on