SQL CREATE DATABASE
Create database is used for creating databases with the following syntax
CREATE DATABASE database_name
Example: Creating a database named Db_test
CREATE DATABASE Db_test
You can add database tables by using CREATE table.
SQL CREATE TABLE
The CREATE TABLE statement creates a table in the database with the following syntax
CREATE TABLE table_name ( column name 1 data type, column name 2 data type, column name 3 data type, ...)
The data type (DATA_TYPE) specifies what data type the column content holds, and the table below contains the most commonly used data types in SQL
Data Type |
Description |
Integer (size) int (size) smallint (size) tinyint (size) |
Holds integers only. Specify the maximum number of digits within the parentheses. |
Decimal (SIZE,D) Numeric (SIZE,D) |
Accommodates numbers with decimals. "Size" Specifies the maximum number of digits. "D" Specifies the maximum number of digits to the right of the decimal point. |
char (size) |
Holds a fixed-length string (which can hold letters, numbers, and special characters). Specifies the length of the string in parentheses. |
varchar (size) |
Accommodates variable-length strings that can hold letters, numbers, and special characters. Specifies the maximum length of the string in parentheses. |
Date (YYYYMMDD) |
accommodate the date. |
CREATE Table Instance
Create a table named "Persons" that contains 5 columns with the column names: Id_p, LastName, FirstName, Address, city
CREATE TABLE ( id_p int, LastName varchar (255), FirstName varchar (255), Address varchar (255) , City varchar (255))
The data type of the id_p column is int, which contains integers. The data type of the remaining 4 columns is varchar, with a maximum length of 255 characters.
An empty "Persons" table looks like this:
id_p |
LastName |
FirstName |
Address |
| City
|
|
|
|
|
You can use the INSERT into statement to write data to an empty table.
SQL Advanced Applications (create DATABASE, create TABLE)