This article focuses on the functionality and usage of the SQL Create Table command.
A Relational Database Management System stores data in form of relations. A relation comprises of tuples and attributes. In layman terms, relation means a table comprising of rows and columns. A tuple is a row, whereas an attribute is a column.
You can implement the example of this article in two ways:
- By installing SQL in your local machine.
- On any online SQL compiler.
2. About Create Table Command in SQL
SQL Create Table command is used to create a new table in the database. You can also create a new table from a pre-existing table. Note that to create a table, you need to have an existing database.
3. SQL Create Table Syntax
Now, let us look at the syntax for the Create Table command.
CREATE TABLE tableName ( columnName1 datatype1, columnName2 datatype2, columnName3 datatype3);
4. SQL Create Table Example
- First of all, create a database. Let us create a database named example using the Create Database command.
Create Database example;
Then you have to use the database created above to create table.
2. With that, you can now create a table using the Create table command. Let us say – we are creating a table named student data. The table has 3 columns. The columns are studentName , studentId, and studentAge where the first column is of type varchar, the others are integers.
CREATE TABLE studentData( studentName varchar(20), studentId number, studentAge number);
The describe command is used to check the structure of the table that you created using
SQL Create table command.
This article also discusses the
SQL Create Table command’s functionality and usage through the example.
SQL Create Table command is one of the most fundamental commands in SQL. It also touches upon the relational database terminologies – relations, tuples, and attributes.
6. Download the source code
You should download the source code to implement the functionality of
SQL Create Table command.
You can download the full source code of this example here: SQL Create Table Example