Create and alter table statements
In which different scenarios can we use these statements?
You use the CREATE TABLE statement to create a table. At the time of creation of the table you can specify the columns of the table, their datatypes and constraints. You can find more info about the usage of the CREATE TABLE statement here. Below is an example of declaring a table which contains information about the Olympic Games.
CREATE TABLE olympic (
host_year INT NOT NULL PRIMARY KEY,
host_nation VARCHAR(40) NOT NULL,
host_city VARCHAR(20) NOT NULL,
opening_date DATE NOT NULL,
closing_date DATE NOT NULL,
mascot VARCHAR(20) ,
slogan VARCHAR(40) ,
introduction VARCHAR(1500)
)
In case your application evolves and you need to modify the database structure you will most probably need to issue an ALTER TABLE statement. You will need to issue an ALTER TABLE statement if you need to add, drop or modify a column, a constraint or an index. Read more about the ALTER TABLE statement here.