Create the following tables. The underlined bold column names are the primary ke
ID: 3880506 • Letter: C
Question
Create the following tables. The underlined bold column names are the primary keys. Make sure to specify the primary and foreign key constraints in your create table statements.
customer: (cus_code:integer, cus_lname:varchar(20), cus_fname:varchar(20), cus_initial:char, cus_areacode:integer,cus_phone:integer).
invoice: (inv_number:integer, cus_code:integer, inv_date:date,
foreign key cus_code references customer(cus_code))
line: (inv_number:integer, prod_code:integer ,line_units:integer,
foreign key (inv_number) references Invoice(inv_number),
foreign key (prod_code) references Product (prod_code) )
product:(prod_code:integer, prod_desc:varchar(50), prod_price:integer, prod_quant:integer,vend_code:integer,
foreign key (vend_code) referenecs Vendor(vend_code))
vendor:(vend_code:integer,vend_name:varchar(30),vend_contact:varchar(30),vend_areacode:integer,vend_phone:integer)
Explanation / Answer
Syntax for creating table in sql
create table tablename
(
col1 datatype,col2 datatype...........coln datatype);
1) create table customer(cus_code int,cus_lname varchar(20),cus_fname varchar(20),cus_initial char(1),
cus_areacode int,cus_phone int,primary key (cus_code));
2) create table invoice(inv_number int,cus_code int,inv_date date,foreign key (cus_code) references customer(cus_code));
3) create table vendor(vend_code int,vend_name varchar(30),vend_contact varchar(30),vend_areacode int,
vend_phone int,primary key (vend_code));
4) create table product(prod_code int,prod_desc varchar(50),prod_price int,prod_quant int,
vend_code int, primary key (prod_code),foreign key (vend_code) references vendor(vend_code));
5) create table line(inv_number int,prod_code int, line_units int,
foreign key (inv_number) references invoice(inv_number),
foreign key (prod_code) references product(prod_code));
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.