DEV Community

Cover image for SQL DDL STATEMENTS


rutikab12 profile image Rutik Bhoyar ・2 min read

Apology for the delay of post.
In this post we will try to learn about how to create table in SQL using SQL CREATE Query.

First of all you need to know that why SQL statements are used, they are used for interacting with entities, attributes means tables and columns in short and their tuples in relational database.

SQL statements fall in two different categories: 1) Data Definition Language(DDL) 2) Data Manipulation Language(DML).
DDL statements are used to define,change or drop database objects such as tables. Common DDL statements type includes :
i)CREATE : Used to creating tables and defining columns.
ii)ALTER : Used for altering tables including adding and dropping columns and modifying datatype.
iii)TRUNCATE : Used for deleting data in a table but not the table itself.
iv)DROP: Used for deleting data.

Syntax-- CREATE TABLE table_name
coulmn_name1 datatype optional parameter

You use the create table query followed by the table name you want to give and then with the columns name separated by commas.

Author_name varchar(10) PRIMARY KEY NOT NULL,
Price char(40),
Year char(4),
The name of the table will be BOOK, and its attributes such as Author_name, Price, Year, etc. will be the columns of the table.n this table, we will also assign the Author_name attribute as the Primary Key, so that no duplicate values can exist.

Now you know that the CREATE TABLE statement includes definition of attributes of columns in the table, including Names of columns Datatypes of columns And other Optional values if required such as the Primary Key constraint.

In next post we will cover other three DDL statement.

Discussion (0)

Editor guide