There are two CREATE statements available in SQL:
- CREATE DATABASE
- CREATE TABLE
A Database is defined as a structured set of data. So, in SQL the very first step to store the data in a well structured manner is to create a database. The CREATE DATABASE statement is used to create a new database in SQL.
CREATE DATABASE database_name; database_name: name of the database.
This query will create a new database in SQL and name the database as my_database.
CREATE DATABASE my_database;
We have learned above about creating databases. Now to store the data we need a table to do that. The CREATE TABLE statement is used to create a table in SQL. We know that a table comprises of rows and columns. So while creating tables we have to provide all the information to SQL about the names of the columns, type of data to be stored in columns, size of the data etc. Let us now dive into details on how to use CREATE TABLE statement to create tables in SQL.
CREATE TABLE table_name ( column1 data_type(size), column2 data_type(size), column3 data_type(size), .... ); table_name: name of the table. column1 name of the first column. data_type: Type of data we want to store in the particular column. For example,int for integer data. size: Size of the data we can store in a particular column. For example if for a column we specify the data_type as int and size as 10 then this column can store an integer number of maximum 10 digits.
This query will create a table named Students with three columns, ROLL_NO, NAME and SUBJECT.
CREATE TABLE Students ( ROLL_NO int(3), NAME varchar(20), SUBJECT varchar(20), );
This query will create a table named Students. The ROLL_NO field is of type int and can store an integer number of size 3. The next two columns NAME and SUBJECT are of type varchar and can store characters and the size 20 specifies that these two fields can hold maximum of 20 characters.
This article is contributed by Harsh Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- SQL | CREATE DOMAIN
- Neo4j Create Constraint
- Neo4j Create Index
- Neo4j Create Node
- Neo4j Create Relationship
- Create database in Cassandra
- SQL | Create Table Extension
- MySQL | CREATE USER Statement
- How to create Swipe Navigation in an Android App
- Create, Alter and Drop schema in MS SQL Server
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- Create a database on Relational Database Service (RDS) of Amazon Web Services(AWS)
- Complete Interview Preparation With Doubt Assistance - INR 90 Lakh Cashback Pool Offer!!
- GeeksforGeeks Skill-Dependence Days 2020 - A Battle Against Unemployment