Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
Understanding the SQL CREATE TABLE Statement - SQL CREATE TABLE Statement

Understanding the SQL CREATE TABLE Statement

Posted on January 9, 2025January 9, 2025 By Rishabh saini No Comments on Understanding the SQL CREATE TABLE Statement

SQL CREATE TABLE Statement

The CREATE TABLE statement is a fundamental SQL command used to define a new table within a database. This command allows you to specify the table name, define its columns, and set the data type for each column. Additionally, you can apply constraints such as NOT NULL, PRIMARY KEY, or UNIQUE to maintain data integrity.

Complete Advance AI topics:- CLICK HERE
Complete Python Course with Advance topics:-Click here

SQL CREATE TABLE Statement

Basic Syntax

Here’s the general syntax for creating a table:

CREATE TABLE table_name (  
    column1 data_type constraint,  
    column2 data_type constraint,  
    column3 data_type constraint,  
    ...  
    columnN data_type constraint  
);  

Key Points:

  • Table Name: Every table must have a unique name.
  • Columns and Data Types: Each column requires a name and a data type that specifies the kind of data it will hold (e.g., INT, VARCHAR, DATE).
  • Constraints: Constraints like NOT NULL and PRIMARY KEY enforce rules on the data in the table.

Note: The data types may vary depending on the database system. For instance:

  • Oracle uses NUMBER for numeric values.
  • MySQL uses INT for integer values.

Example: Creating a STUDENTS Table

The following example demonstrates how to create a STUDENTS table with ID as the primary key:

CREATE TABLE STUDENTS (  
    ID INT NOT NULL,  
    NAME VARCHAR(20) NOT NULL,  
    AGE INT NOT NULL,  
    ADDRESS CHAR(25),  
    PRIMARY KEY (ID)  
);  

To verify the table’s creation, use the DESC command:

DESC STUDENTS;  

The output will display the structure of the STUDENTS table, including its columns, data types, and constraints.

Creating Tables in Different SQL Databases

MySQL Example

CREATE TABLE Employee (  
    EmployeeID INT,  
    FirstName VARCHAR(255),  
    LastName VARCHAR(255),  
    Email VARCHAR(255),  
    AddressLine VARCHAR(255),  
    City VARCHAR(255)  
);  

Oracle Example

CREATE TABLE Employee (  
    EmployeeID NUMBER(10),  
    FirstName VARCHAR2(255),  
    LastName VARCHAR2(255),  
    Email VARCHAR2(255),  
    AddressLine VARCHAR2(255),  
    City VARCHAR2(255)  
);  

Microsoft SQL Server Example

CREATE TABLE Employee (  
    EmployeeID INT,  
    FirstName VARCHAR(255),  
    LastName VARCHAR(255),  
    Email VARCHAR(255),  
    AddressLine VARCHAR(255),  
    City VARCHAR(255)  
);  

Creating a Table Using an Existing Table

You can create a new table by copying the structure and data from an existing table.

Syntax:

CREATE TABLE new_table_name AS  
SELECT column1, column2, ...  
FROM old_table_name  
WHERE condition;  

Example:

CREATE TABLE EmployeeCopy AS  
SELECT EmployeeID, FirstName, Email  
FROM Employee;  

The new table EmployeeCopy will have the same structure as Employee but will only include the specified columns and rows matching the WHERE condition.

Adding a Primary Key with CREATE TABLE

The PRIMARY KEY constraint uniquely identifies each record in a table.

Single-Column Primary Key (MySQL):

CREATE TABLE Employee (  
    EmployeeID INT NOT NULL,  
    FirstName VARCHAR(255) NOT NULL,  
    LastName VARCHAR(255),  
    City VARCHAR(255),  
    PRIMARY KEY (EmployeeID)  
);  

Single-Column Primary Key (SQL Server / Oracle):

CREATE TABLE Employee (  
    EmployeeID INT NOT NULL PRIMARY KEY,  
    FirstName VARCHAR(255) NOT NULL,  
    LastName VARCHAR(255),  
    City VARCHAR(255)  
);  

Composite Primary Key:

You can define a PRIMARY KEY on multiple columns and name the constraint for clarity:

CREATE TABLE Employee (  
    EmployeeID INT NOT NULL,  
    FirstName VARCHAR(255) NOT NULL,  
    LastName VARCHAR(255),  
    City VARCHAR(255),  
    CONSTRAINT PK_Employee PRIMARY KEY (EmployeeID, FirstName)  
);  

Download New Real Time Projects :-Click here


create table in sql with primary key
Understanding the SQL CREATE TABLE Statement
insert into table sql
create table student details in sql
create table and insert data sql
create student table in sql and insert values
SQL CREATE TABLE Statement
sql data types
sql online compiler
create table in sql server
sql create table primary key
sql insert into
sql create table statement example
sql create table statement w3schools
sql create table statement oracle

 

Post Views: 728
SQL Tutorial Tags:create table statement, create table statement access, create table statement sql, create table statements, create table statements mysql, data definition statements, Database Management, database management system, insert into statement, insert into statements, relational database management system, sql create index statement, sql create table statement, sql server table create statement, sql server: create table statement, sql statement

Post navigation

Previous Post: How to Create a Dictionary in Python
Next Post: Banking Management System Using JAVA With Free Source Code

More Related Articles

SQL Temporary Tables SQL Temporary Tables: A Handy Tool for Developers SQL Tutorial
SQL TRUNCATE TABLE SQL TRUNCATE TABLE: A Comprehensive Guide SQL Tutorial
SQL SELECT Statement Exploring the SQL SELECT Statement: Your Ultimate Guide SQL Tutorial

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. SQL SELECT from Multiple Tables
  2. SQL WITH Clause
  3. SQL UPDATE with JOIN
  4. SQL DELETE ROW: How to Remove Records from a Table
  5. Understanding SQL CROSS JOIN with Examples
  6. IN vs EXISTS in SQL: A Complete Guide

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Blog Site In PHP And MYSQL With Source Code || Best Project
  9. Online Bike Rental Management System Using PHP and MySQL
  10. E learning Website in php with Free source code
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Agentic RAG AI System Using Python – Complete Final Year Project Guide
  • AI-Powered Online Examination System with Face Detection Using PHP & MySQL
  • Real-Time Medical Queue & Appointment System with Django
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital

Most Viewed Posts

  • Top Large Language Models in 2025 (8,632)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,252)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,913)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme