top of page
Search
Writer's pictureHarsh Jain

What Is SQL Table Creation And How Does It Work?

A table is basically a collection of data stored in the database which consists of tables and rows. Data is logically organized in rows and columns just like we do in a spreadsheet. The rows in the table represent a unique record and the columns represent the field of the record.


Tables are essential elements of a database and can contain more than one table and can be modelled as relational. Let's understand SQL table creation.



SQL table creation


SQL Table Creation


To create a table using SQL, you use the CREATE TABLE command.


The syntax to which is:

CREATE TABLE table_name (

column1 datatype,

column2 datatype,

column3 datatype,

....

);


Here, the column1, 2 and 3 specify the names of the columns in the table

The datatype specifies the type of data that the column holds. The CREATE TABLE tells the database what you want to do. The name of the table follows the CREATE TABLE command.


The bracket is followed by the list defining each column and the type of data it will have.


Let’s take this example for SQL table creation: We will create a table named Customers


CREATE TABLE Customer (

ID int,

Name varchar(50),

LastName varchar(50),

Address varchar(250),

City varchar(50)

Email varchar(250)

Phone varchar(50)


);



The int and varchar (x) are data types which tell us what could be stored n that field. Like int can store numbers and varchar(x) can store variable characters up to the length x.


In this article, we have just covered the fundamentals and this is just the beginning of SQL table creation.


4 views0 comments

Recent Posts

See All

Comments


Post: Blog2_Post
bottom of page