- Script (init.sql)
Create a database called ddl_exercise
. Create a table named people
in this database, with columns id integer
, name varchar(50)
and surname varchar(50)
.
Column id
should be an auto incrementing primary key.
- Script (migration1.sql)
- Now add columns
age integer
,sex char(1)
andposition varchar(50)
to this table. - increase the size for
surname
to 100 characters. - get rid of
position
column (we changed our mind)
- Script (seeds.sql)
Fill the table with some rows (it's up to you to make them) so that we have 5 men and 5 women in it and:
- 2 people of less than 10 years,
- 2 people between 10-20,
- 2 people between 20-30,
- 2 people between 30-40,
- 2 people older than 40 years.
- Script (migration2.sql)
- Add column
title varchar(10)
and set it for all the people in following way- people older than 20 should have it set to
Eng.
- people older than 30 years should have it set to
Dr.
- people older than 40 years should have it set to
Prof.
- people older than 20 should have it set to
- Delete all men younger than 10 years
- Create table
positions
with columnsid integer
,person_id integer
,position varchar(50)
and set theperson_id
as a foreign key to tablepeople
and its columnid
- Create
professors
, which should be a copy (schema & data) ofpeople
table, but holding only records about professors.