how to create table in sql

3 minutes ago 1
how to create table in sql

To create a table in SQL, the basic syntax is:

sql

CREATE TABLE table_name (
    column1 datatype [constraint],
    column2 datatype [constraint],
    column3 datatype [constraint],
    ...
);
  • Use the keyword CREATE TABLE followed by the desired table name.
  • Inside parentheses, define column names with their data types and optional constraints.
  • Separate each column definition with a comma.
  • End the statement with a semicolon.

Example:

sql

CREATE TABLE Employees (
    EmployeeID int PRIMARY KEY,
    FirstName varchar(50),
    LastName varchar(50),
    Age int,
    Address varchar(100)
);

This creates a table named "Employees" with five columns, specifying data types and a primary key constraint on EmployeeID.