-
Notifications
You must be signed in to change notification settings - Fork 0
/
creating_database.sql
54 lines (42 loc) · 1.19 KB
/
creating_database.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
-- creating database
create database p9_pets ;
-- using database p9_pets
use p9_pets ;
show tables;
-- creating tables owners
CREATE TABLE owners (
ownerid int primary key,
name varchar(20),
surname varchar(20),
streetaddress varchar(50),
city varchar(20),
state varchar(20),
zipcode int
);
-- creating table pets
CREATE TABLE pets (
petid int primary key,
name varchar(10),
kind enum("Dog","Cat","Parrot","Hamster"),
gender enum("M","F"),
age int,
ownerid int ,
constraint ownerid_fk_1 foreign key(ownerid) references owners(ownerid)
);
-- creating table for stored procedures
CREATE TABLE proceduredetails (
proceduretype varchar(20),
proceduresubcode int primary key,
description varchar(20),
price int
);
-- creating table procedurehistory and adding petid and procudure subcod as foregin key
CREATE TABLE procedurehistory (
petid int,
proceduredate date,
proceduretype varchar(20),
proceduresubcode int ,
constraint petid_fk_1 foreign key(petid) references pets(petid),
constraint prdcode_fk_3 foreign key(proceduresubcode) references proceduredetails(proceduresubcode)
);
-- drop database p9_pets;