The SQL CREATE TABLE statement is used to create a new table in a database. The syntax for the CREATE TABLE statement is as follows:
CREATE TABLE table_name (
column1 datatype [optional_parameters],
column2 datatype [optional_parameters],
...
columnN datatype [optional_parameters]
);
Where table_name is the name of the new table that you want to create, column1 through columnN are the names of the columns in the table, and datatype specifies the type of data that each column can store.
For example, let’s say we want to create a table named “employees” with four columns: “id”, “first_name”, “last_name”, and “email”. We can use the following CREATE TABLE statement:
CREATE TABLE employees (
id INT NOT NULL PRIMARY KEY,
first_name VARCHAR(50) NOT NULL,
last_name VARCHAR(50) NOT NULL,
email VARCHAR(100) NOT NULL UNIQUE
);
In this example, we define four columns with their respective data types and optional parameters. The id column is defined as an integer and is set as the primary key for the table. The first_name and last_name columns are defined as variable-length strings of up to 50 characters, and the email column is defined as a unique string of up to 100 characters.
In addition to the data type, we can also specify optional parameters for each column. For example, we have used the NOT NULL parameter to ensure that the id, first_name, last_name, and email columns cannot contain NULL values. We have also used the PRIMARY KEY parameter to specify the id column as the primary key for the table and the UNIQUE parameter to ensure that the email column contains unique values.
Once the CREATE TABLE statement is executed, the new table is created in the database, and we can start inserting data into it using the INSERT INTO statement.
Learners TV is a website that is designed to educate users and provide instructional material on particular subjects and topics.