CREATE
Example
Section titled “Example”CREATE DATABASE IF NOT EXISTS testDB;Output
Section titled “Output”Query OK, 1 row affected (0.01 sec)Explanation
Section titled “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
Section titled “Example”CREATE TABLE employees ( ID INT PRIMARY KEY, name VARCHAR (100), birth_year INT, job_title VARCHAR (100));Output
Section titled “Output”CREATE TABLEExplanation
Section titled “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
Section titled “Example”CREATE DATABASE TestDatabase;Output
Section titled “Output”Command(s) completed successfully.Explanation
Section titled “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
Section titled “Example”CREATE TABLE employees ( employee_id NUMBER(6), first_name VARCHAR2(20), last_name VARCHAR2(25), email VARCHAR2(25), phone_number VARCHAR2(20), hire_date DATE, job_id VARCHAR2(10), salary NUMBER(8, 2), manager_id NUMBER(6), department_id NUMBER(4));Output
Section titled “Output”Table EMPLOYEES created.Explanation
Section titled “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
Section titled “Example”CREATE TABLE employees ( id INTEGER PRIMARY KEY, first_name TEXT NOT NULL, last_name TEXT NOT NULL, email TEXT NOT NULL UNIQUE);Output
Section titled “Output”Query OK, 0 rows affected (0.01 sec)Explanation
Section titled “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.