CREATE
CREATE is an SQL command used to create a database or a table. Specifically, this command constructs new tables, databases, views, or index in SQL. Different database systems use several forms of CREATE like CREATE DATABASE, CREATE TABLE, CREATE INDEX, CREATE VIEW, etc. for distinct purposes. By invoking the right parameters and inputs, developers can use CREATE command to effectively structure their database system.
Example
Output
Explanation
This SQL command creates a new database named testDB
, if there isn’t already a database with that name existing. The IF NOT EXISTS
clause ensures no error occurs if the testDB
already exists. The output Query OK, 1 row affected (0.01 sec)
indicates that the execution of the command was successful.
Example
Output
Explanation
In this example, the CREATE TABLE
statement creates a new table named ‘employees’ in the database. The new table has four columns: ID, name, birth_year, and job_title. The ID column is a key primary and it does not accept NULL values. The name and job_title columns are of variable-length character type, specified by VARCHAR (100), and the birth_year is of integer type. The output message CREATE TABLE
confirms the successful creation of the table.
Example
Output
Explanation
The SQL statement creates a new database in SQL Server. The database is named TestDatabase
. The output message validates that the command has been executed and the database has been created successfully.
Example
Output
Explanation
The CREATE TABLE
statement defined a new table called employees
in the database. The table has the columns employee_id
, first_name
, last_name
, email
, phone_number
, hire_date
, job_id
, salary
, manager_id
, and department_id
with the specified data types and sizes. After executing the CREATE TABLE
statement, the system returns a message indicating that the table was successfully created.
Example
Output
Explanation
The above SQL code creates a new table named employees
in the database. The table has four columns: id
, first_name
, last_name
, and email
. The id
is an INTEGER type and is the primary key of the table which uniquely identifies every row. The first_name
, last_name
, and email
columns are of TEXT type. The NOT NULL
constraint makes sure that these columns cannot have NULL values. The UNIQUE
constraint on the email
column ensures that all entries in this column are unique.