Skip to content

Instantly share code, notes, and snippets.

@spion
Forked from eduardoleon/existing.sql
Last active November 9, 2015 04:58
Show Gist options
  • Save spion/d60382ff2787967cb104 to your computer and use it in GitHub Desktop.
Save spion/d60382ff2787967cb104 to your computer and use it in GitHub Desktop.
create table male
( male_id int not null
, primary key (male_id) );
create table female
( female_id int not null
, primary key (female_id) );
create table name
( id int not null
, name text not null
, primary key (id));
create view gender as
select 'm' as gender, male_id as id from male
union
select 'f' as gender, female_id as id from female;
create view person as
select n.id, n.name, g.gender
from name n join gender g on n.id = g.id;
insert into name values (1, 'John');
insert into male values (1);
insert into name values (2, 'Jane');
insert into female values(2);
select * from person;
update name set name = @new_name where id = @person_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment