In: Computer Science
create database sample;
use sample;
create table customer (custno int auto_increment primary key,
firstname varchar(20), middle varchar(20), lastname varchar(20),
address varchar(60), telnum1 varchar(10), telnum2 varchar(10),
telnum3 varchar(10), pin varchar(6), email varchar(30));
create table accttype (id int primary key, type varchar(10));
insert into accttype (id, type) values (1,'check');
insert into accttype (id, type) values (2,'save');
insert into accttype (id, type) values (3,'cd');
insert into accttype (id, type) values (4,'visa');
insert into accttype (id, type) values (5,'debit');
insert into accttype (id, type) values (6,'home');
create table account (acctno int auto_increment primary key, custno
int, type int, balance double, index acpair(acctno,custno), foreign
key (custno) references customer(custno), foreign key (type)
references accttype(id));
insert into customer
(firstname,middle,lastname,address,telnum1,pin,email)
values('John','Quincy','Adams','PO Box 1234, Allentown, PA
18101','6102561034','2564','[email protected]');
insert into customer
(firstname,middle,lastname,address,telnum1,telnum2,pin,email)
values('Richard','Milhouse','Nixon','120 Union Avenue, Bethlehem,
PA
18018','6102111210','4843201457','9873','[email protected]');
insert into customer
(firstname,middle,lastname,address,telnum1,telnum2,pin,email)
values('David','Dwight','Eisenhower','34 Main Street, Folgelsville,
PA
18025','6104561234','4849871200','63712','[email protected]');
insert into account (custno, type, balance) values
(1,1,1356.75);
insert into account (custno, type, balance) values
(1,2,10000.00);
insert into account (custno, type, balance) values
(1,3,50000.00);
insert into account (custno, type, balance) values
(1,4,129.13);
insert into account (custno, type, balance) values (1,5,0.0);
insert into account (custno, type, balance) values
(2,1,121.19);
insert into account (custno, type, balance) values
(2,2,8194.10);
insert into account (custno, type, balance) values
(2,4,2015.99);
insert into account (custno, type, balance) values (2,5,0.0);
insert into account (custno, type, balance) values
(3,2,563.00);
insert into account (custno, type, balance) values
(3,3,20000.00);
insert into account (custno, type, balance) values
(3,6,1000000.00);
create table checking (acctno int, custno int, primary key (acctno,
custno), index acpair(acctno,custno), foreign key (acctno,custno)
references account(acctno, custno));
insert into checking (acctno, custno) values (1,1);
insert into checking (acctno, custno) values (6,2);
create table saving (acctno int, custno int, apr double, primary
key (acctno, custno), index acpair(acctno,custno), foreign key
(acctno,custno) references account(acctno,custno));
insert into saving (acctno, custno, apr) values (2,1,0.25);
insert into saving (acctno, custno, apr) values (7,2,0.015);
insert into saving (acctno, custno, apr) values (10,3,0.005);
create table cd (acctno int, custno int, apr double, mature date,
primary key (acctno, custno), index acpair(acctno,custno), foreign
key (acctno,custno) references account(acctno,custno));
insert into cd (acctno, custno, apr, mature) values
(3,1,0.05,'2020-09-10');
insert into cd (acctno, custno, apr, mature) values
(11,3,0.045,'2020-12-31');
create table visa (acctno int, custno int, minpay double, due date,
rate double, primary key (acctno, custno), index
acpair(acctno,custno), foreign key (acctno,custno) references
account(acctno,custno));
insert into visa (acctno, custno, minpay, due, rate) values
(4,1,25.00,'2020-09-19',0.15);
insert into visa (acctno, custno, minpay, due, rate) values
(8,2,25.00,'2020-09-21',0.15);
create table debit (acctno int, custno int, primary key (acctno,
custno), index acpair(acctno,custno), foreign key (acctno,custno)
references account(acctno,custno));
insert into debit (acctno, custno) values (5,1);
insert into debit (acctno, custno) values (9,2);
create table home (acctno int, custno int, payment double, due
date, rate double, term int, primary key (acctno, custno), index
acpair(acctno,custno), foreign key (acctno,custno) references
account(acctno,custno));
insert into home (acctno, custno, payment, due, rate, term) values
(12,3,3696.19,'2020-09-30',0.02,30);
# It is a good idea to do all further work with the sample database
as a regular user
# as opposed to the root user. To get up yourself as a user, invoke
the mysql command
# as the root user then enter at the mysql prompt:
# mysql> create user <yourID>@localhost identified by
'securepasswd';
# check to make sure this worked with:
# mysql> select user, host from mysql.user;
# Then give yourID permissions to use the sample DB:
# mysql> grant all privileges on sample.* to
'yourID'@'localhost';
# To verify, log into mysql with the command:
# $ mysql -u yourID -p
# and enter the password. When logged in enter:
# mysql use sample;
# To verify enter:
# mysql> show tables;
Creating user with name test and password testpass
Showing all the tables
I hope this will help.