Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

CREATE Statement in SQL

The primary use of the CREATE TABLE statement is to create new tables in a database. Before one starts running queries and storing data in a DB, it is mandatory to create a certain table where the data would be stored. A table would be where all the data is stored in a database, and hence we use the CREATE statement in SQL.

In this article, we will dive deeper into CREATE Statement in SQL according to the GATE Syllabus for (Computer Science Engineering) CSE. Keep reading ahead to learn more.

Table of Contents

What is a CREATE Statement in SQL?

Two CREATE statements are available in the Structured Query Language:

1. CREATE A TABLE

2. CREATE A DATABASE

Creating a Database

The database is defined in the form of a data structured set. Thus, in SQL, the first step to storing the data in a well-structured manner is the creation of a database. This CREATE DATABASE statement is mainly used for the creation of a new database in SQL.

The Syntax would be:

CREATE DATABASE name_of_database;

name_of_database: the name of the DB

Example Query

The query given below will create a new DB in SQL. Then it will name the DB as my_database.

CREATE DATABASE my_database;

Creating a Table

We have learned about creating databases. Now, if we want to store the data, a table would be needed. The CREATE TABLE statement is used to create a table in SQL. A table consists of various rows and columns; thus, while creating the tables, one has to provide all the data and information to SQL regarding the name of the column, type of information to be stored, size of the data, and many more. We will now dive into the details on how we can use the CREATE TABLE statement in order to create tables in SQL.

The Syntax goes like this:

CREATE TABLE name_of_table

(

column_A data_type(size),

column_B data_type(size),

column_C data_type(size),

….

);

name_of_table

column_A

data_type { like int for integers}

size: Size of data stores in a column

number of maximum 10 digits

Example Query

This query creates a table named Candidates that has three columns, ID_NO, NAME and COURSE.

CREATE TABLE Candidates

(

ID_NO int(3),

NAME varchar(20),

COURSE varchar(20),

);

Such a query would create a table named Candidates. The ID_NO field is of the int data type. It can store some integer numbers of size 3. The two columns that come next, i.e., NAME and COURSE are of type varchar. These can store characters. Here, the size 20 defines that these fields can hold a maximum of 20 characters in total.

Keep learning and stay tuned to get the latest updates on the GATE Exam along with Eligibility Criteria, GATE Syllabus for CSE (Computer Science Engineering), GATE CSE Notes, GATE CSE Question Paper, and more.

Also Explore,

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*