SQL CREATE TABLE | Learn SQL

SQL CREATE TABLE

SQL Create Table is used to create and define a table (Design) in database. If you want to create a table then first you give name of table then specify column name and data types of particular column, you can also specify constraints like primary key, foreign key, unique key etc.

How to create table using query?

SQL Create Table | Tech-Mirror
SQL Create Table | Tech-Mirror

The data type of the columns in a table may vary from one database to another. For example, NUMBER is supported in Oracle database for integer value whereas INT is supported in MySQL.

Example to create a Employee_Master table with ID as primary key and NOT NULL are the constraint showing that these fields cannot be NULL or Empty while inserting records in the table.

This SQL CREATE TABLE example creates a table called Employee_Master which has Four columns.

  • First column is called Employee_id which is created as an INT datatype and can not contain NULL values.
  • Second column is called Last_name which is a VARCHAR datatype (50 maximum characters in length) and also can not contain NULL values.
  • Third column is called First_name which is a VARCHAR datatype but can contain NULL values.
  • Fourth column is called salary which is a DECIMAL datatype which can contain NULL values.

Now you want to specify primary key in a column then we modify above table as,

You can also create table with the help of design in any data base tool without writing a single line of query and also directly insert records in it.

For More SQL Select

Leave a Reply

Your email address will not be published. Required fields are marked *