AWS Global Infrastructure

Databases

Topics Covered
  • Cassandra (14 Blogs)
  • MongoDB Dev and Admin (15 Blogs)
  • MySQL (55 Blogs)
  • SQL Essentials Training and Certification (9 Blogs)
SEE MORE

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-widget-banner-bg

CREATE TABLE in SQL – Everything You Need To Know About Creating Tables in SQL

Published on Aug 07,2019 551 Views
8 / 37 Blog from Introduction to SQL

MI-new-launch

myMock Interview Service for Real Tech Jobs

myMock-mobile-banner-bg

myMock Interview Service for Real Tech Jobs

  • Mock interview in latest tech domains i.e JAVA, AI, DEVOPS,etc
  • Get interviewed by leading tech experts
  • Real time assessment report and video recording

SQL or Structured Query Language consists of various commands to handle relational databases. These commands are segregated into various categories such as DDL, DML, DCL, and TCL. One important query out of the lot is the CREATE Table query from the DDL commands. So, in this article on Create Table in SQL, you will learn about CREATE TABLE statement in the following sequence:

SQL - Create Table in SQL - Edureka

    1. What is Create Table query?
    2. Create Table syntax
    3. How to create a table using another table?

What is Create Table query?

The create table statement is used to create a table for the database you are using. This table can have n rows and m columns based on the requirement. So, with the help of this query, you can basically store data in the form of rows and columns.

Next, in this article on create table in SQL, let us see the syntax of Create statement.

Create Table syntax

The syntax of the CREATE TABLE statement is as follows:

CREATE TABLE tablename (
column1 data type,
column2 data type,
column3 data type,
column4 data type,
....
columnN data type);

Here, the column parameters represent the name of the columns to be included in the table. Similarly,  the data type parameter represents the type of data columns can store. Example: character, integer, date, varchar, etc.

Example:

CREATE TABLE students (
studentID int,
studentname varchar(255),
parentname varchar(255),
address varchar(255),
phonenumber int
);

Output:

studentIDstudentnameparentnameaddressphonenumber

Now, once you create the tables, you can go forward and insert values into the table by using the Insert queryBut, what if you had to create a table using another existing table? How will you do that?

So, next, in this article on create table in SQL, let us look into the same.

How to create a table using another table?

To create another table from an existing table, you have to use the following syntax:

CREATE TABLE newtablename AS
SELECT column1, column2,..., columnN
FROM existingtablename
WHERE ....;

Here, you are trying to create a new table from an existing one. Also, you are choosing the required columns from the existing table, based on a condition. But, mentioning a condition is not mandatory.

Example:

CREATE TABLE sampletable AS
SELECT studentID, studentname
FROM students;

Output:

studentIDstudentname

Note: The new table gets the same column definitions as that of the old one. Also, if your existing table has any values stored, then automatically the new table will be filled with those values.

With this, we come to an end to this article. I hope you understood, how to use the CREATE TABLE in SQL. If you wish to learn more about MySQL and get to know this open-source relational database, then check out our MySQL DBA Certification Training which comes with instructor-led live training and real-life project experience. This training will help you understand MySQL in-depth and help you achieve mastery over the subject.

Got a question for us? Please mention it in the comments section of this article and I will get back to you.

Comments
0 Comments

Browse Categories

webinar REGISTER FOR FREE WEBINAR
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP

Subscribe to our Newsletter, and get personalized recommendations.