In: Computer Science
create table candidate (
cand_id varchar(12) primary key, --
cand_id
name varchar(40)
-- cand_nm
);
create table contributor (
contbr_id integer primary key,
name varchar(40),
-- contbr_nm
city varchar(40),
-- contbr_city
state varchar(40),
-- contbr_st
zip varchar(20),
-- contbr_zip
employer varchar(60),
-- contbr_employer
occupation varchar(40)
-- contbr_occupation
);
create table contribution (
contb_id integer primary key,
cand_id varchar(12),
-- cand_id
contbr_id varchar(12),
-- contbr_id
amount numeric(6,2),
-- contb_receipt_amt
date varchar(20),
-- contb_receipt_dt
election_type varchar(20),
-- election_tp
tran_id varchar(20),
-- tran_id
foreign key (cand_id) references candidate,
foreign key (contbr_id) references contributor
);
___________________________________________________
All three tables will be written to a single SQL file.
___________________________________________________
-- 16. set the SQLite output to be a file named
'campaign-normal.sql'
.output 'campaign-normal.sql'
-- 17. output the candidate schema, and then all candidate rows
as SQL
-- insert statements.
-- Hint: the SQLite .mode command allows you to select that you
want
-- rows of a query to be output as SQL insert statements, and
the
-- table name to be specified.
-- 18. output the contributor schema, and then all contributor rows
as SQL
-- insert statements.
-- 19. output the contribution schema, and then all contribution
rows as SQL
-- insert statements.
-- 20. set the SQL output so that it no longer goes to a file
mysql>create table candidate(
-> cand_id varchar(12) primary key, -- cand_id
-> name varchar(40) -- cand_nm
-> );
Query OK, 0 rows affected (0.31 sec)
mysql> insert into candidate values(1,'john');
Query OK, 1 row affected (0.11 sec)
mysql> insert into candidate values(2,'ram');
Query OK, 1 row affected (0.09 sec)
mysql> insert into candidate values(3,'sham');
Query OK, 1 row affected (0.09 sec)
mysql> insert into candidate values(4,'sita');
Query OK, 1 row affected (0.10 sec)
mysql> desc candidate;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| cand_id | varchar(12) | NO | PRI | NULL | |
| name | varchar(40) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
2 rows in set (0.41 sec)
mysql> select * from candidate;
+---------+------+
| cand_id | name |
+---------+------+
| 1 | john |
| 2 | ram |
| 3 | sham |
| 4 | sita |
+---------+------+
4 rows in set (0.05 sec)
mysql> create table contributor (
-> contbr_id integer primary key,
-> name varchar(40), -- contbr_nm
-> city varchar(40), -- contbr_city
-> state varchar(40), -- contbr_st
-> zip varchar(20), -- contbr_zip
-> employer varchar(60), -- contbr_employer
-> occupation varchar(40) -- contbr_occupation
-> );
Query OK, 0 rows affected (0.19 sec)
mysql> insert into contributor
values(12,'chinu','csn','maharastra','fdt','sales
person','mba');
Query OK, 1 row affected (0.10 sec)
mysql> insert into contributor
values(13,'tina','nsk','maharastra','nng','softde
veloper','engg');
Query OK, 1 row affected (0.09 sec)
mysql> insert into contributor
values(14,'hiina','pune','maharastra','wer','doct
or','mbbs');
Query OK, 1 row affected (0.09 sec)
mysql> desc contributor;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| contbr_id | int(11) | NO | PRI | NULL | |
| name | varchar(40) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| state | varchar(40) | YES | | NULL | |
| zip | varchar(20) | YES | | NULL | |
| employer | varchar(60) | YES | | NULL | |
| occupation | varchar(40) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
7 rows in set (0.17 sec)
mysql> select * from contributor;
+-----------+-------+------+------------+------+---------------+------------+
| contbr_id | name | city | state | zip | employer | occupation
|
+-----------+-------+------+------------+------+---------------+------------+
| 12 | chinu | csn | maharastra | fdt | salesperson | mba |
| 13 | tina | nsk | maharastra | nng | softdeveloper | engg |
| 14 | hiina | pune | maharastra | wer | doctor | mbbs |
+-----------+-------+------+------------+------+---------------+------------+
3 rows in set (0.00 sec)
mysql> insert into contributor
values(15,'ram','mumbai','maharastra','wer','doct
or','mbbs');
Query OK, 1 row affected (0.11 sec)
mysql> insert into contributor
values(16,'sham','nsk','maharastra','nng','softde
veloper','engg');
Query OK, 1 row affected (0.09 sec)
mysql> insert into contributor
values(17,'sita','csn','maharastra','fdt','salesp
erson','mba');
Query OK, 1 row affected (0.10 sec)
mysql> desc contributor;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| contbr_id | int(11) | NO | PRI | NULL | |
| name | varchar(40) | YES | | NULL | |
| city | varchar(40) | YES | | NULL | |
| state | varchar(40) | YES | | NULL | |
| zip | varchar(20) | YES | | NULL | |
| employer | varchar(60) | YES | | NULL | |
| occupation | varchar(40) | YES | | NULL | |
+------------+-------------+------+-----+---------+-------+
7 rows in set (0.09 sec)
mysql> select * from contributor;
+-----------+-------+--------+------------+------+---------------+------------+
| contbr_id | name | city | state | zip | employer | occupation
|
+-----------+-------+--------+------------+------+---------------+------------+
| 12 | chinu | csn | maharastra | fdt | salesperson | mba |
| 13 | tina | nsk | maharastra | nng | softdeveloper | engg |
| 14 | hiina | pune | maharastra | wer | doctor | mbbs |
| 15 | ram | mumbai | maharastra | wer | doctor | mbbs |
| 16 | sham | nsk | maharastra | nng | softdeveloper | engg |
| 17 | sita | csn | maharastra | fdt | salesperson | mba |
+-----------+-------+--------+------------+------+---------------+------------+
6 rows in set (0.05 sec)
mysql> create table contribution( contb_id integer primary key,
cand_id varchar(
12),contbr_id integer,amount numeric(6,2),date
varchar(20),election_type varchar
(20),trans_id varchar(20),foreign key(cand_id)references
candidate(cand_id),fore
ign key(contbr_id)references contributor(contbr_id) );
Query OK, 0 rows affected (0.17 sec)
mysql> desc contribution;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| contb_id | int(11) | NO | PRI | NULL | |
| cand_id | varchar(12) | YES | MUL | NULL | |
| contbr_id | int(11) | YES | MUL | NULL | |
| amount | decimal(6,2) | YES | | NULL | |
| date | varchar(20) | YES | | NULL | |
| election_type | varchar(20) | YES | | NULL | |
| trans_id | varchar(20) | YES | | NULL | |
+---------------+--------------+------+-----+---------+-------+
7 rows in set (0.07 sec)
mysql> insert into contribution
values(44,2,15,5677.00,'22jun2015','yes','tyeyw6
7')
-> ;
Query OK, 1 row affected (0.09 sec)
mysql> insert into contribution
values(45,3,16,7678.00,'29jun2015','no','iuiuo78
');
Query OK, 1 row affected (0.09 sec)
mysql> insert into contribution
values(46,4,17,9999.00,'23jun2015','yes','mnmnm3
4');
Query OK, 1 row affected (0.09 sec)
mysql> desc contribution;
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| contb_id | int(11) | NO | PRI | NULL | |
| cand_id | varchar(12) | YES | MUL | NULL | |
| contbr_id | int(11) | YES | MUL | NULL | |
| amount | decimal(6,2) | YES | | NULL | |
| date | varchar(20) | YES | | NULL | |
| election_type | varchar(20) | YES | | NULL | |
| trans_id | varchar(20) | YES | | NULL | |
+---------------+--------------+------+-----+---------+-------+
7 rows in set (0.01 sec)
mysql> select * from contribution;
+----------+---------+-----------+---------+-----------+---------------+--------
--+
| contb_id | cand_id | contbr_id | amount | date | election_type |
trans_i
d |
+----------+---------+-----------+---------+-----------+---------------+--------
--+
| 44 | 2 | 15 | 5677.00 | 22jun2015 | yes | tyeyw67
|
| 45 | 3 | 16 | 7678.00 | 29jun2015 | no | iuiuo78
|
| 46 | 4 | 17 | 9999.00 | 23jun2015 | yes | mnmnm34
|
+----------+---------+-----------+---------+-----------+---------------+--------
--+
3 rows in set (0.00 sec)
mysql>