The SQL Create Database Statement: Syntax
The SQL Create Database Statement: Syntax
Syntax
Example
Tip: Make sure you have admin privilege before creating any database. Once a database is
created, you can check it in the list of databases with the following SQL command: SHOW
DATABASES;
Syntax
Note: Be careful before dropping a database. Deleting a database will result in loss of complete
information stored in the database!
Example
Tip: Make sure you have admin privilege before dropping any database.
Syntax
BACKUP DATABASE databasename
TO DISK = 'filepath';
Syntax
Example
Tip: Always back up the database to a different drive than the actual database. Then, if you get a
disk crash, you will not lose your backup file along with the database.
Example
Syntax
The column parameters specify the names of the columns of the table.
The datatype parameter specifies the type of data the column can hold (e.g. varchar, integer, date,
etc.).
Example
The new table gets the same column definitions. All columns or specific columns can be
selected.
If you create a new table using an existing table, the new table will be filled with the existing
values from the old table.
Syntax
The following SQL creates a new table called "TestTables" (which is a copy of the "Customers"
table):
Example
Syntax
Note: Be careful before dropping a table. Deleting a table will result in loss of complete
information stored in the table!
Example
Syntax
The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
Example
The following SQL deletes the "Email" column from the "Customers" table:
Example
Syntax
Constraints are used to limit the type of data that can go into a table. This ensures the accuracy
and reliability of the data in the table. If there is any violation between the constraint and the data
action, the action is aborted.
Constraints can be column level or table level. Column level constraints apply to a column, and
table level constraints apply to the whole table.