Advertisement
Superloup10

create_table.sql

Dec 25th, 2016
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.08 KB | None | 0 0
  1. /* Table utilisateur */
  2. CREATE TABLE IF NOT EXISTS user_account
  3. (
  4.     id_user INT NOT NULL AUTO_INCREMENT,
  5.     name_user VARCHAR(20) NOT NULL,
  6.     firstname VARCHAR(20) NOT NULL,
  7.     CONSTRAINT pk_user_account PRIMARY KEY (id_user)
  8. )ENGINE = InnoDB;
  9.  
  10. /* Table compte banquaire */
  11. CREATE TABLE IF NOT EXISTS bank_account
  12. (
  13.     id_account INT NOT NULL AUTO_INCREMENT,
  14.     type_account VARCHAR(20) NOT NULL, /* (Courant, Épargne, etc...) */
  15.     real_balance FLOAT NOT NULL DEFAULT 0.0,
  16.     anticipate_balance FLOAT NOT NULL DEFAULT 0.0,
  17.     id_user INT NOT NULL,
  18.     CONSTRAINT p_bank_account PRIMARY KEY (id_account),
  19.     CONSTRAINT fk_bank_account_id_user FOREIGN KEY (id_user) REFERENCES user_account(id_user)
  20. )ENGINE = InnoDB;
  21.  
  22. /* Table chèque */
  23. CREATE TABLE IF NOT EXISTS cheque_account
  24. (
  25.     id_cheque INT NOT NULL AUTO_INCREMENT,
  26.     first_number_cheque VARCHAR(7),
  27.     prev_number_cheque VARCHAR(7),
  28.     last_number_cheque VARCHAR(7),
  29.     CONSTRAINT pk_cheque_account PRIMARY KEY (id_cheque),
  30.     CONSTRAINT chk_cheque_account_first_number_cheque CHECK(first_number_cheque < last_number_cheque),
  31.     CONSTRAINT chk_cheque_account_prev_number_cheque CHECK(prev_number_cheque BETWEEN first_number_cheque AND last_number_cheque),
  32.     CONSTRAINT chk_cheque_account_last_number_cheque CHECK(last_number_cheque > first_number_cheque)
  33. )ENGINE = InnoDB;
  34.  
  35. /* Table paiement */
  36. CREATE TABLE IF NOT EXISTS payment_account
  37. (
  38.     id_payment INT NOT NULL AUTO_INCREMENT,
  39.     name_payment VARCHAR(20) NOT NULL,
  40.     id_cheque INT NOT NULL,
  41.     CONSTRAINT pk_payment_account PRIMARY KEY (id_payment),
  42.     CONSTRAINT fk_payment_account_id_cheque FOREIGN KEY (id_cheque) REFERENCES cheque_account(id_cheque)
  43. )ENGINE = InnoDB;
  44.  
  45. /* Table type de dépense */
  46. CREATE TABLE IF NOT EXISTS type_expend_account
  47. (
  48.     id_type_expend INT NOT NULL AUTO_INCREMENT,
  49.     name_type_expend VARCHAR(20) NOT NULL,
  50.     CONSTRAINT pk_type_expend_account PRIMARY KEY (id_type_expend)
  51. )ENGINE = InnoDB;
  52.  
  53. /* Table pour calculer le solde réel et le solde anticipé */
  54. /* Table dépense */
  55. CREATE TABLE IF NOT EXISTS expend_account
  56. (
  57.     id_expend INT NOT NULL AUTO_INCREMENT,
  58.     amount FLOAT NOT NULL,
  59.     desc_expend VARCHAR(20),
  60.     date_expend DATE NOT NULL,
  61.     id_payment INT NOT NULL,
  62.     id_account INT NOT NULL,
  63.     id_type_expend INT NOT NULL,
  64.     anticipate BOOLEAN NOT NULL DEFAULT TRUE,
  65.     CONSTRAINT pk_expend_account PRIMARY KEY (id_expend),
  66.     CONSTRAINT fk_expend_account_id_account FOREIGN KEY (id_account) REFERENCES bank_account(id_account),
  67.     CONSTRAINT fk_expend_account_id_type_expend FOREIGN KEY (id_type_expend) REFERENCES type_expend_account(id_type_expend)
  68. )ENGINE = InnoDB;
  69.  
  70. /* Table revenu */
  71. CREATE TABLE IF NOT EXISTS income_account
  72. (
  73.     id_income INT NOT NULL AUTO_INCREMENT,
  74.     amount FLOAT NOT NULL,
  75.     desc_income VARCHAR(20),
  76.     date_income DATE NOT NULL,
  77.     id_payment INT NOT NULL,
  78.     id_account INT NOT NULL,
  79.     anticipate BOOLEAN NOT NULL DEFAULT TRUE,
  80.     CONSTRAINT pk_income_account PRIMARY KEY (id_income),
  81.     CONSTRAINT fk_income_account_id_account FOREIGN KEY (id_account) REFERENCES bank_account(id_account)
  82. )ENGINE = InnoDB;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement