• Home
  • Jobs
  • Courses
  • Certifications
  • Companies
  • Online IDE
  • Login
  • Signup
MySQL
  • Introduction To MySQL
  • MySQL RDBMS
  • MySQL SQL
  • MySQL SELECT Statement
  • MySQL WHERE Clause
  • MySQL AND, OR And NOT Operators
  • MySQL ORDER BY Keyword
  • MySQL INSERT INTO Statement
  • MySQL NULL Values
  • MySQL UPDATE Statement
  • MySQL DELETE Statement
  • MySQL LIMIT Clause
  • MySQL MIN() And MAX() Functions
  • MySQL COUNT(), AVG() And SUM() Functions
  • MySQL LIKE Operator
  • MySQL Wildcards
  • MySQL IN Operator
  • MySQL BETWEEN
  • MySQL Aliases
  • MySQL Joins
  • MySQL INNER JOIN Keyword
  • MySQL LEFT JOIN Keyword
  • MySQL RIGHT JOIN Keyword
  • MySQL CROSS JOIN Keyword
  • MySQL Self Join
  • MySQL UNION Operator
  • MySQL GROUP BY Statement
  • MySQL HAVING Clause
  • MySQL EXISTS Operator
  • MySQL ANY And ALL Operators
  • MySQL INSERT INTO SELECT Statement
  • MySQL CASE Statement
  • MySQL NULL Functions
  • MySQL Comments
  • MySQL Operators
  • MySQL CREATE DATABASE Statement
  • MySQL DROP DATABASE Statement
  • MySQL CREATE TABLE Statement
  • MySQL DROP TABLE Statement
  • MySQL ALTER TABLE Statement
  • MySQL Constraints
  • MySQL NOT NULL Constraint
  • MySQL UNIQUE Constraint
  • MySQL PRIMARY KEY Constraint
  • MySQL FOREIGN KEY Constraint
  • MySQL CHECK Constraint
  • MySQL DEFAULT Constraint
  • MySQL CREATE INDEX Statement
  • MySQL AUTO INCREMENT Field
  • MySQL Working With Dates
  • MySQL Views
  • MySQL Data Types
  • MySQL Functions
  • Home
  • Courses
  • MySQL
  • MySQL CREATE TABLE Statement

MySQL CREATE TABLE Statement

Previous Next

The MySQL CREATE TABLE Statement

The CREATE TABLE statement is used to create a new table in a database.

Syntax

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
The column parameters specify the names of the columns of the table.

The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date, etc.).



Practice Excercise Practice now

MySQL CREATE TABLE Example

The following example creates a table called "Persons" that contains five columns: PersonID, LastName, FirstName, Address, and City:
 

CREATE TABLE Persons (
    PersonID int,
    LastName varchar(255),
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255)
);
The PersonID column is of type int and will hold an integer.

The LastName, FirstName, Address, and City columns are of type varchar and will hold characters, and the maximum length for these fields is 255 characters.

The empty "Persons" table will now look like this:
PersonID LastName FirstName Address City
         


The empty "Persons" table can now be filled with data with the SQL INSERT INTO statement.



Practice Excercise Practice now

Create Table Using Another Table

A copy of an existing table can also be created using CREATE TABLE.

The new table gets the same column definitions. All columns or specific columns can be selected.

If you create a new table using an existing table, the new table will be filled with the existing values from the old table.

Syntax

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

The following SQL creates a new table called "TestTables" (which is a copy of the "Customers" table): 
 
CREATE TABLE TestTable AS
SELECT customername, contactname
FROM customers;



Practice Excercise Practice now

Previous Next
COMPANY
  • About us
  • Careers
  • Contact Us
  • In Press
  • People
  • Companies List
Products
  • Features
  • Coding Assessments
  • Psychometric Assessment
  • Aptitude Assessments
  • Tech/Functional Assessments
  • Video Assessment
  • Fluency Assessment
  • Campus
 
  • Learning
  • Campus Recruitment
  • Lateral Recruitment
  • Enterprise
  • Education
  • K 12
  • Government
OTHERS
  • Blog
  • Terms of Services
  • Privacy Policy
  • Refund Policy
  • Mart Category
Partner
  • Partner Login
  • Partner Signup

Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP