Advertisement
kolinsol

my database

Apr 30th, 2017
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 22.96 KB | None | 0 0
  1. create table account
  2. (
  3.     debit double default '0' null,
  4.     credit double default '0' null,
  5.     type enum('PERSONAL', 'DEPOSIT', 'DEPOSIT-PERCENTAGE') default 'passive' not null,
  6.     amount double default '0' null,
  7.     person_id tinyint null,
  8.     deposit_id tinyint null,
  9.     currency_id tinyint default '4' not null,
  10.     operation_type enum('active', 'passive', 'active-passive') default 'passive' not null,
  11.     code char(13) not null,
  12.     id tinyint not null auto_increment
  13.         primary key,
  14.     credit_id tinyint null,
  15.     constraint account_code_uindex
  16.         unique (code),
  17.     constraint account_id_uindex
  18.         unique (id),
  19.     constraint account_fk_credit
  20.         foreign key (credit_id) references bank.credit (id),
  21.     constraint account_fk_currency
  22.         foreign key (currency_id) references bank.currency (id)
  23. )
  24. ;
  25.  
  26. create index account_fk_currency
  27.     on account (currency_id)
  28. ;
  29.  
  30. create index account_fk_person
  31.     on account (person_id)
  32. ;
  33.  
  34. create index account_fk_deposit
  35.     on account (deposit_id)
  36. ;
  37.  
  38. create index account_fk_credit
  39.     on account (credit_id)
  40. ;
  41.  
  42. create table bank_fund
  43. (
  44.     id int not null
  45.         primary key,
  46.     debit double default '0' not null,
  47.     credit double default '0' not null,
  48.     type enum('active', 'passive', 'active-passive') not null,
  49.     amount double default '0' null,
  50.     currency_id tinyint not null
  51. )
  52. ;
  53.  
  54. create table city
  55. (
  56.     id tinyint not null auto_increment
  57.         primary key,
  58.     name varchar(25) not null
  59. )
  60. ;
  61.  
  62. create table contact
  63. (
  64.     id tinyint not null auto_increment
  65.         primary key,
  66.     phone_number char(13) not null,
  67.     email varchar(255) not null,
  68.     address varchar(255) not null,
  69.     city_id tinyint null,
  70.     constraint contact_phone_number_uindex
  71.         unique (phone_number),
  72.     constraint contact_email_uindex
  73.         unique (email),
  74.     constraint contact_fk_city
  75.         foreign key (city_id) references bank.city (id)
  76. )
  77. ;
  78.  
  79. create index contact_fk_city
  80.     on contact (city_id)
  81. ;
  82.  
  83. create table credit
  84. (
  85.     amount double not null,
  86.     start_date date null,
  87.     end_date date null,
  88.     person_id tinyint not null,
  89.     currency_id tinyint not null,
  90.     code char(7) not null,
  91.     id tinyint not null auto_increment
  92.         primary key,
  93.     credit_type_id tinyint null,
  94.     status enum('PENDING', 'ACCEPTED', 'DECLINED', 'EXPIRED') default 'PENDING' not null,
  95.     period tinyint not null,
  96.     constraint credit_id_uindex
  97.         unique (id),
  98.     constraint credit_fk_person
  99.         foreign key (person_id) references bank.person (id),
  100.     constraint credit_fk_currency
  101.         foreign key (currency_id) references bank.currency (id),
  102.     constraint credit_fk_deposit_type
  103.         foreign key (credit_type_id) references bank.credit_type (id)
  104. )
  105. ;
  106.  
  107. create index credit_fk_currency
  108.     on credit (currency_id)
  109. ;
  110.  
  111. create index credit_fk_deposit_type
  112.     on credit (credit_type_id)
  113. ;
  114.  
  115. create index credit_fk_person
  116.     on credit (person_id)
  117. ;
  118.  
  119. create table credit_type
  120. (
  121.     id tinyint not null auto_increment
  122.         primary key,
  123.     name varchar(45) not null,
  124.     percentage double not null,
  125.     min_amount double default '100' not null,
  126.     max_amount double default '50000' not null,
  127.     min_period tinyint default '6' not null,
  128.     max_period tinyint default '12' not null,
  129.     constraint deposit_type_id_uindex
  130.         unique (id),
  131.     constraint deposit_type_name_uindex
  132.         unique (name)
  133. )
  134. ;
  135.  
  136. create table currency
  137. (
  138.     id tinyint not null auto_increment
  139.         primary key,
  140.     name varchar(25) not null
  141. )
  142. ;
  143.  
  144. create table deposit
  145. (
  146.     amount double not null,
  147.     start_date date null,
  148.     end_date date null,
  149.     person_id tinyint not null,
  150.     currency_id tinyint not null,
  151.     code char(7) not null,
  152.     id tinyint not null auto_increment
  153.         primary key,
  154.     deposit_type_id tinyint null,
  155.     status enum('PENDING', 'ACCEPTED', 'DECLINED', 'EXPIRED') default 'PENDING' not null,
  156.     period tinyint not null,
  157.     constraint deposit_id_uindex
  158.         unique (id),
  159.     constraint deposit_fk_person
  160.         foreign key (person_id) references bank.person (id),
  161.     constraint deppsit_fk_currency
  162.         foreign key (currency_id) references bank.currency (id),
  163.     constraint deposit_fk_deposit_type
  164.         foreign key (deposit_type_id) references bank.deposit_type (id)
  165. )
  166. ;
  167.  
  168. create index deppsit_fk_currency
  169.     on deposit (currency_id)
  170. ;
  171.  
  172. create index deposit_fk_person
  173.     on deposit (person_id)
  174. ;
  175.  
  176. create index deposit_fk_deposit_type
  177.     on deposit (deposit_type_id)
  178. ;
  179.  
  180. alter table account
  181.     add constraint account_fk_deposit
  182.         foreign key (deposit_id) references Bank.deposit (id)
  183.             on delete cascade
  184. ;
  185.  
  186. create table deposit_type
  187. (
  188.     id tinyint not null auto_increment
  189.         primary key,
  190.     name varchar(45) not null,
  191.     percentage double not null,
  192.     min_amount double default '100' not null,
  193.     max_amount double default '50000' not null,
  194.     min_period tinyint default '6' not null,
  195.     max_period tinyint default '12' not null,
  196.     constraint deposit_type_id_uindex
  197.         unique (id),
  198.     constraint deposit_type_name_uindex
  199.         unique (name)
  200. )
  201. ;
  202.  
  203. create table login
  204. (
  205.     username varchar(45) not null,
  206.     password varchar(45) not null,
  207.     id tinyint not null auto_increment
  208.         primary key,
  209.     constraint login_username_uindex
  210.         unique (username)
  211. )
  212. ;
  213.  
  214. create table passport
  215. (
  216.     serial_number char(9) not null,
  217.     issue_facility varchar(255) not null,
  218.     issue_date date not null,
  219.     expire_date date not null,
  220.     address varchar(255) not null,
  221.     city_id tinyint not null,
  222.     id tinyint not null auto_increment
  223.         primary key,
  224.     constraint passport_serial_number_uindex
  225.         unique (serial_number),
  226.     constraint passport_fk_city
  227.         foreign key (city_id) references bank.city (id)
  228. )
  229. ;
  230.  
  231. create index passport_fk_city
  232.     on passport (city_id)
  233. ;
  234.  
  235. create table person
  236. (
  237.     id tinyint not null auto_increment
  238.         primary key,
  239.     firstname varchar(25) not null,
  240.     secondname varchar(25) not null,
  241.     lastname varchar(25) not null,
  242.     birth_date date not null,
  243.     pension tinyint(1) not null,
  244.     military tinyint(1) not null,
  245.     contact_id tinyint null,
  246.     sex enum('Мужской', 'Женский') null,
  247.     passport_id tinyint null,
  248.     login_id tinyint null,
  249.     constraint person_passport_id_uindex
  250.         unique (passport_id),
  251.     constraint person_contact_id_uindex
  252.         unique (contact_id),
  253.     constraint person_login_id_uindex
  254.         unique (login_id),
  255.     constraint person_fk_passport
  256.         foreign key (passport_id) references bank.passport (id),
  257.     constraint person_fk_contact
  258.         foreign key (contact_id) references bank.contact (id),
  259.     constraint person_fk_login
  260.         foreign key (login_id) references bank.login (id)
  261. )
  262. ;
  263.  
  264. alter table account
  265.     add constraint account_fk_person
  266.         foreign key (person_id) references Bank.person (id)
  267.             on delete cascade
  268. ;
  269.  
  270. create table transaction_log
  271. (
  272.     id tinyint not null auto_increment
  273.         primary key,
  274.     from_account varchar(255) not null,
  275.     to_account varchar(255) not null,
  276.     amount int not null,
  277.     type enum('USABLE', 'USED', 'REUSEABLE') not null,
  278.     constraint transaction_log_id_uindex
  279.         unique (id)
  280. )
  281. ;
  282.  
  283. create procedure acceptCredit (IN input_credit_id tinyint, OUT output_credit_code char(7))  
  284. BEGIN
  285.     update Bank.credit
  286.     set status = 'ACCEPTED'
  287.     where id = input_credit_id;
  288.     select code from Bank.credit
  289.     where id = input_credit_id
  290.     into output_credit_code;
  291.   end;
  292.  
  293. create procedure acceptDeposit (IN input_deposit_id tinyint, OUT output_deposit_code char(7))  
  294. BEGIN
  295.     update Bank.deposit
  296.     set status = 'ACCEPTED'
  297.     where id = input_deposit_id;
  298.     select code from Bank.deposit
  299.     where id = input_deposit_id
  300.     into output_deposit_code;
  301.   end;
  302.  
  303. create procedure addContactInfo (IN input_phone_number varchar(15), IN input_email varchar(255), IN input_address varchar(255), IN input_city_id tinyint, OUT output_id tinyint)  
  304. begin
  305. insert into contact(phone_number, email, address, city_id)
  306. values(input_phone_number, input_email, input_address, input_city_id);
  307. select last_insert_id() into output_id;
  308. end;
  309.  
  310. create procedure addCredit (IN input_code char(7), IN input_period tinyint, IN input_person_id tinyint, IN input_currency_id tinyint, IN input_credit_type_id tinyint, IN input_status varchar(45), IN input_amount double, OUT output_id tinyint)  
  311. BEGIN
  312.     insert into credit(code, period, person_id, currency_id, credit_type_id,
  313.                        status, amount)
  314.     values(input_code, input_period, input_person_id, input_currency_id,
  315.            input_credit_type_id, input_status, input_amount);
  316.     SELECT last_insert_id() into output_id;
  317.   END;
  318.  
  319. create procedure addDeposit (IN input_code char(7), IN input_period tinyint, IN input_person_id tinyint, IN input_currency_id tinyint, IN input_deposit_type_id tinyint, IN input_status varchar(45), IN input_amount double, OUT output_id tinyint)  
  320. BEGIN
  321.     insert into deposit(code, period, person_id, currency_id, deposit_type_id,
  322.                         status, amount)
  323.       values(input_code, input_period, input_person_id, input_currency_id,
  324.             input_deposit_type_id, input_status, input_amount);
  325.     SELECT last_insert_id() into output_id;
  326.   END;
  327.  
  328. create procedure addDepositAccount (IN input_code char(13), IN input_type varchar(45), IN input_person_id tinyint, IN input_deposit_id tinyint, IN input_currency_id tinyint, IN input_amount double, OUT output_id tinyint)  
  329. BEGIN
  330.     insert into Bank.account(code, type, person_id, deposit_id, currency_id, amount)
  331.     values(input_code, input_type, input_person_id, input_deposit_id,
  332.            input_currency_id, input_amount);
  333.     select last_insert_id() into output_id;
  334.   end;
  335.  
  336. create procedure addDepositPercentageAccount (IN input_code char(13), IN input_type varchar(45), IN input_person_id tinyint, IN input_deposit_id tinyint, IN input_currency_id tinyint, OUT output_id tinyint)  
  337. BEGIN
  338.     insert into Bank.account(code, type, person_id, deposit_id, currency_id)
  339.     values(input_code, input_type, input_person_id, input_deposit_id,
  340.            input_currency_id);
  341.     select last_insert_id() into output_id;
  342.   end;
  343.  
  344. create procedure addLoginInfo (IN input_username varchar(255), IN input_password varchar(255), OUT output_id tinyint)  
  345. begin
  346. insert into login(username, password)
  347. values(input_username, input_password);
  348. select last_insert_id() into output_id;
  349. end;
  350.  
  351. create procedure addPassport (IN input_serial_number char(9), IN input_issue_facility varchar(255), IN input_issue_date date, IN input_expire_date date, IN input_city_id tinyint, IN input_address varchar(255), OUT output_id tinyint)  
  352. begin
  353. insert into passport(serial_number, issue_facility, issue_date, expire_date, city_id, address)
  354. value(input_serial_number, input_issue_facility, input_issue_date, input_expire_date, input_city_id, input_address);
  355. select last_insert_id() into output_id;
  356. end;
  357.  
  358. create procedure addPerson (IN input_firstname varchar(25), IN input_secondname varchar(25), IN input_lastname varchar(25), IN input_birth_date date, IN input_sex varchar(15), IN input_pension tinyint(1), IN input_military tinyint(1), OUT output_id tinyint)  
  359. begin
  360.     insert into Bank.person(firstname, secondname, lastname, birth_date, sex, pension, military)
  361.     values(input_firstname, input_secondname, input_lastname, input_birth_date, input_sex, input_pension, input_military);
  362.     select last_insert_id() into output_id;
  363.     end;
  364.  
  365. create procedure addPersonalAccount (IN input_code char(13), IN input_type varchar(45), IN input_person_id tinyint, OUT output_id tinyint)  
  366. BEGIN
  367.     insert into Bank.account(code, type, person_id)
  368.     values(input_code, input_type, input_person_id);
  369.     select last_insert_id() into output_id;
  370.   end;
  371.  
  372. create procedure changePassword (IN input_username varchar(255), IN input_new_password varchar(255))  
  373. begin
  374.     update Bank.login
  375.       set password = input_new_password
  376.     where username = input_username;
  377.   end;
  378.  
  379. create procedure checkLogin (IN input_username varchar(255), IN input_password varchar(255), OUT permission tinyint(1))  
  380. BEGIN
  381.     declare temp_password VARCHAR(255);
  382.     set permission = FALSE;
  383.     select password into temp_password
  384.     from Bank.login
  385.     where username = input_username;
  386.     if (input_password = temp_password) THEN
  387.       set permission = TRUE;
  388.     END IF;
  389.   END;
  390.  
  391. create procedure createCity (IN input_name varchar(45), OUT output_id tinyint)  
  392. begin
  393. insert into city(name) value(input_name);
  394. select last_insert_id() into output_id;
  395. end;
  396.  
  397. create procedure declineCredit (IN input_credit_id tinyint, OUT output_credit_code char(7))  
  398. BEGIN
  399.     update Bank.credit
  400.     set status = 'DECLINED'
  401.     where id = input_credit_id;
  402.     select code from Bank.credit
  403.     where id = input_credit_id
  404.     into output_credit_code;
  405.   end;
  406.  
  407. create procedure declineDeposit (IN input_deposit_id tinyint, OUT output_deposit_code char(7))  
  408. BEGIN
  409.     update Bank.deposit
  410.     set status = 'DECLINED'
  411.     where id = input_deposit_id;
  412.     select code from Bank.deposit
  413.     where id = input_deposit_id
  414.     into output_deposit_code;
  415.   end;
  416.  
  417. create procedure deletePerson (IN input_person_id tinyint)  
  418. BEGIN
  419.     declare temp_passport_id, temp_contact_id, temp_login_id TINYINT;
  420.     select passport_id into temp_passport_id
  421.     from person
  422.     where id = input_person_id;
  423.     select contact_id into temp_contact_id
  424.     from person
  425.     where id = input_person_id;
  426.     select login_id into temp_login_id
  427.     from person
  428.     where id = input_person_id;
  429.     delete from person
  430.       where id = input_person_id;
  431.     delete from passport
  432.       where id = temp_passport_id;
  433.     delete from contact
  434.       where id = temp_contact_id;
  435.     delete from login
  436.       where id = temp_login_id;
  437.   END;
  438.  
  439. create procedure getAllCreditTypeIds ()  
  440. BEGIN
  441.     select id from Bank.credit_type;
  442.   END;
  443.  
  444. create procedure getAllDepositTypeIds ()  
  445. BEGIN
  446.         select id from Bank.deposit_type;
  447.     END;
  448.  
  449. create procedure getAllPersonIds ()  
  450. BEGIN
  451.         select id from person
  452.           where login_id IS NOT NULL
  453.                 AND contact_id IS NOT NULL
  454.                 AND passport_id IS NOT null;
  455.     END;
  456.  
  457. create procedure getCities ()  
  458. (
  459. select name from city);
  460.  
  461. create procedure getCityIdByName (IN input_name varchar(45), OUT output_id tinyint)  
  462. begin
  463. select id into output_id
  464. from city where name=input_name;
  465. end;
  466.  
  467. create procedure getCityNameById (IN input_id tinyint, OUT output_name varchar(45))  
  468. begin
  469. select name into output_name
  470. from city where id=input_id;
  471. end;
  472.  
  473. create procedure getContactInfo (INOUT inoutput_id tinyint, OUT output_phone_number char(13), OUT output_email varchar(255), OUT output_address varchar(255), OUT output_city_id tinyint)  
  474. BEGIN
  475.         select phone_number, email, address, city_id
  476.            into output_phone_number, output_email, output_address, output_city_id
  477.         from contact
  478.             where id = inoutput_id;
  479.     END;
  480.  
  481. create procedure getContactInfoId (IN input_person_id tinyint, OUT output_contact_id tinyint)  
  482. begin
  483. select contact_id into output_contact_id
  484. from person where id=input_person_id;
  485. end;
  486.  
  487. create procedure getCredit (INOUT inoutput_id tinyint, OUT output_code char(7), OUT output_period tinyint, OUT output_person_id tinyint, OUT output_currency_id tinyint, OUT output_credit_type_id tinyint, OUT output_status varchar(45), OUT output_amount double)  
  488. begin
  489.   select code, period, person_id, currency_id, credit_type_id,
  490.          status, amount
  491.   into output_code, output_period, output_person_id, output_currency_id,
  492.       output_credit_type_id, output_status, output_amount
  493.     from Bank.credit
  494.     where id = inoutput_id;
  495.     end;
  496.  
  497. create procedure getCreditType (INOUT inoutput_id tinyint, OUT output_name varchar(45), OUT output_percentage double, OUT output_min_amount double, OUT output_max_amount double, OUT output_min_period tinyint, OUT output_max_period tinyint)  
  498. BEGIN
  499.     select  name, percentage, min_amount, max_amount, min_period, max_period
  500.     into output_name, output_percentage, output_min_amount, output_max_amount,
  501.       output_min_period, output_max_period
  502.     from Bank.credit_type
  503.     where id =  inoutput_id;
  504.   END;
  505.  
  506. create procedure getCurrencies ()  
  507. (
  508. select name from currency
  509. );
  510.  
  511. create procedure getCurrencyIdByName (IN input_name varchar(45), OUT output_id tinyint)  
  512. begin
  513. select id into output_id
  514. from currency where name=input_name;
  515. end;
  516.  
  517. create procedure getDeposit (INOUT inoutput_id tinyint, OUT output_code char(7), OUT output_period tinyint, OUT output_person_id tinyint, OUT output_currency_id tinyint, OUT output_deposit_type_id tinyint, OUT output_status varchar(45), OUT output_amount double)  
  518. begin
  519.   select code, period, person_id, currency_id, deposit_type_id,
  520.          status, amount
  521.   into output_code, output_period, output_person_id, output_currency_id,
  522.       output_deposit_type_id, output_status, output_amount
  523.     from Bank.deposit
  524.     where id = inoutput_id;
  525.     end;
  526.  
  527. create procedure getDepositType (INOUT inoutput_id tinyint, OUT output_name varchar(45), OUT output_percentage double, OUT output_min_amount double, OUT output_max_amount double, OUT output_min_period tinyint, OUT output_max_period tinyint)  
  528. BEGIN
  529.     select  name, percentage, min_amount, max_amount, min_period, max_period
  530.     into output_name, output_percentage, output_min_amount, output_max_amount,
  531.       output_min_period, output_max_period
  532.     from Bank.deposit_type
  533.     where id =  inoutput_id;
  534.   END;
  535.  
  536. create procedure getLoginInfo (INOUT inoutput_id tinyint, OUT output_username varchar(45), OUT output_password varchar(45))  
  537. BEGIN
  538.         select username, password
  539.            into output_username, output_password
  540.         from login
  541.             where id = inoutput_id;
  542.     END;
  543.  
  544. create procedure getLoginInfoId (IN input_person_id tinyint, OUT output_login_id tinyint)  
  545. begin
  546. select login_id into output_login_id
  547. from person where id=input_person_id;
  548. end;
  549.  
  550. create procedure getPassport (INOUT inoutput_id tinyint, OUT output_issue_facility varchar(255), OUT output_issue_date date, OUT output_expire_date date, OUT output_city_id tinyint, OUT output_address varchar(255), OUT output_serial_number char(9))  
  551. BEGIN
  552.         select issue_facility, issue_date, expire_date, city_id, address, serial_number
  553.            into output_issue_facility, output_issue_date, output_expire_date, output_city_id,
  554.                output_address, output_serial_number
  555.         from passport
  556.             where id = inoutput_id;
  557.     END;
  558.  
  559. create procedure getPassportId (IN input_person_id tinyint, OUT output_passport_id tinyint)  
  560. begin
  561. select passport_id into output_passport_id
  562. from person where id=input_person_id;
  563. end;
  564.  
  565. create procedure getPendingCredits ()  
  566. begin
  567.     select d.id as credit_id, CONCAT(p.secondname, ' ', p.firstname, ' ', p.lastname) as name,
  568.       d.code, CONCAT(dt.percentage, ' %') as percentage,
  569.       CONCAT(d.amount, ' ', c.name) as amount, p.id as person_id
  570.     from Bank.credit as d
  571.       join Bank.person as p
  572.         on d.person_id = p.id
  573.       join Bank.credit_type as dt
  574.         on d.credit_type_id = dt.id
  575.       join Bank.currency as c
  576.         on d.currency_id = c.id
  577.     where d.status = 'PENDING';
  578.   end;
  579.  
  580. create procedure getPendingDeposits ()  
  581. begin
  582.     select d.id as deposit_id, CONCAT(p.secondname, ' ', p.firstname, ' ', p.lastname) as name,
  583.       d.code, CONCAT(dt.percentage, ' %') as percentage,
  584.       CONCAT(d.amount, ' ', c.name) as amount, p.id as person_id
  585.     from Bank.deposit as d
  586.       join Bank.person as p
  587.         on d.person_id = p.id
  588.       join Bank.deposit_type as dt
  589.         on d.deposit_type_id = dt.id
  590.       join Bank.currency as c
  591.         on d.currency_id = c.id
  592.     where d.status = 'PENDING';
  593.   end;
  594.  
  595. create procedure getPerson (INOUT inoutput_id tinyint, OUT output_firstname varchar(255), OUT output_secondname varchar(255), OUT output_lastname varchar(255), OUT output_birth_date date, OUT output_sex varchar(15), OUT output_pension tinyint(1), OUT output_military tinyint(1))  
  596. BEGIN
  597.         select firstname, secondname, lastname, birth_date, sex, pension, military
  598.            into output_firstname, output_secondname, output_lastname, output_birth_date,
  599.              output_sex, output_pension, output_military
  600.         from person
  601.             where id = inoutput_id;
  602.     END;
  603.  
  604. create procedure getPersonByUsername (IN input_username varchar(255), OUT output_person_id tinyint)  
  605. BEGIN
  606.     DECLARE temp_login_id TINYINT;
  607.     select id into temp_login_id
  608.       from login
  609.       where username = input_username;
  610.     select id into output_person_id
  611.       from person
  612.       where login_id = temp_login_id;
  613.   END;
  614.  
  615. create procedure setContactInfo (IN input_person_id tinyint, IN input_contact_id tinyint)  
  616. begin
  617.     update Bank.person
  618.       set contact_id = input_contact_id
  619.     where id = input_person_id;
  620.   end;
  621.  
  622. create procedure setDepositPeriod (IN input_deposit_id tinyint, IN input_start_date date, IN input_end_date date)  
  623. BEGIN
  624.     update Bank.deposit
  625.       set start_date = input_start_date,
  626.         end_date = input_end_date
  627.     WHERE id = input_deposit_id;
  628.   END;
  629.  
  630. create procedure setLoginInfo (IN input_person_id tinyint, IN input_login_id tinyint)  
  631. begin
  632.     update Bank.person
  633.       set login_id = input_login_id
  634.     where id = input_person_id;
  635.   end;
  636.  
  637. create procedure setPassport (IN input_person_id tinyint, IN input_passport_id tinyint)  
  638. begin
  639.     update Bank.person
  640.       set passport_id = input_passport_id
  641.     where id = input_person_id;
  642.   end;
  643.  
  644. create procedure updateContactInfo (IN input_contact_id tinyint, IN input_new_phone_number char(13), IN input_new_email varchar(255), IN input_new_address varchar(255), IN input_new_city_id tinyint)  
  645. begin
  646.     update Bank.contact
  647.       set phone_number = input_new_phone_number,
  648.           email = input_new_email,
  649.           address = input_new_address,
  650.           city_id = input_new_city_id
  651.     where id = input_contact_id;
  652.   end;
  653.  
  654. create procedure updateLoginInfo (IN input_login_id tinyint, IN input_new_username varchar(255), IN input_new_password varchar(255))  
  655. begin
  656.     update Bank.login
  657.       set username = input_new_username, password = input_new_password
  658.     where id = input_login_id;
  659.   end;
  660.  
  661. create procedure updatePassport (IN input_passport_id tinyint, IN input_new_serial_number char(9), IN input_new_issue_facility varchar(255), IN input_new_issue_date date, IN input_new_expire_date date, IN input_new_city_id tinyint, IN input_new_address varchar(255))  
  662. begin
  663.     update Bank.passport
  664.       set serial_number = input_new_serial_number,
  665.           issue_facility = input_new_issue_facility,
  666.           issue_date = input_new_issue_date,
  667.           expire_date = input_new_expire_date,
  668.           city_id = input_new_city_id,
  669.           address = input_new_address
  670.     where id = input_passport_id;
  671.   end;
  672.  
  673. create procedure updatePerson (IN input_person_id tinyint, IN input_new_firstname varchar(255), IN input_new_secondname varchar(255), IN input_new_lastname varchar(255), IN input_new_birth_date date, IN input_new_sex varchar(15), IN input_new_pension tinyint(1), IN input_new_military tinyint(1))  
  674. begin
  675.     update Bank.person
  676.       set firstname = input_new_firstname,
  677.           secondname = input_new_secondname,
  678.           lastname = input_new_lastname,
  679.           birth_date = input_new_birth_date,
  680.           sex = input_new_sex,
  681.           pension = input_new_pension,
  682.           military = input_new_military
  683.     where id = input_person_id;
  684.   end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement