How to create table in SQL ?

In SQL tables are database objects that contain all the data in a database. Data is logically organized in a row-and-column format similar to a spreadsheet.

The number of tables in a database is limited only by the number of objects allowed in a database (2,147,483,647). A standard user-defined table can have up to 1,024 columns. The number of rows in the table is limited only by the storage capacity of the server.

In a table, there are rows and columns, with rows referred to as records and columns referred to as fields. A column consists of data values of a specific type, such as numbers or alphabets, with each row in the database having one value for that column

———————

SQL CREATE TABLE statement is used to create a new table. Each row represents a unique record, and each column represents a field in the record.

Syntax of creating new table is as follow-

CREATE TABLE table_name (
column1 datatype,
column2 datatype,
column3 datatype,
…..
columnN datatype,
);

Explanation:-

  • table_name is the name of the table
  • column1 is the name of the first column
  • column2 is the name of the second column
  • columnN is the name of the last column
  • CREATE TABLE is the keyword that tells the database system what you want to do.

For Example,

CREATE TABLE Students(
ID int,
Name varchar(20),
Address varchar (20)
);

Another example of table with SQL Constraint.

Create Table Employee(
Id Int Not Null,
Name Varchar (20) Not Null,
Age Int Not Null,
Address Char (25),
Salary Decimal (18, 2),
Primary Key (Id)
);