-- Generated by Ora2Pg, the Oracle database Schema converter, version 1.12
-- Copyright 2000 Gilles DAROLD. All rights reserved.
--
-- This program is free software; you can redistribute it and/or modify it under
-- the same terms as Perl itself.
   
BEGIN TRANSACTION;
   
CREATE TABLE "担当者マスタ" (
         "担当者id" numeric NOT NULL,
         "担当者名" varchar(20) NOT NULL,
         "ふりがな" varchar(20) NOT NULL,
         "mgr_id" numeric,
         "生年月日" timestamp NOT NULL,
         "性別" numeric NOT NULL,
         PRIMARY KEY ("担当者id")
);
   
CREATE TABLE "顧客マスタ" (
         "顧客id" numeric NOT NULL,
         "顧客名" varchar(20) NOT NULL,
         "連絡先" varchar(20) NOT NULL,
         PRIMARY KEY ("顧客id")
);
   
CREATE TABLE "売上データ" (
         "伝票番号" numeric NOT NULL,
         "行番号" numeric NOT NULL,
         "処理日" timestamp NOT NULL,
         "商品id" numeric NOT NULL,
         "担当者id" numeric NOT NULL,
         "顧客id" numeric NOT NULL,
         "数量" numeric NOT NULL,
         PRIMARY KEY ("伝票番号","行番号")
);
   
CREATE TABLE "支店担当者マスタ" (
         "支店担当者id" numeric NOT NULL,
         "支店担当者名" varchar(20) NOT NULL,
         "ふりがな" varchar(20) NOT NULL,
         "mgr_id" numeric,
         "生年月日" timestamp NOT NULL,
         "性別" numeric NOT NULL,
         PRIMARY KEY ("支店担当者id")
);
   
CREATE TABLE "商品マスタ" (
         "商品id" numeric NOT NULL,
         "商品名" varchar(30) NOT NULL,
         "グループ名" varchar(20) NOT NULL,
         "仕入単価" numeric,
         "卸単価" numeric,
         PRIMARY KEY ("商品id")
);
   
ALTERTABLE "担当者マスタ" ADD CONSTRAINT fk_mgr FOREIGN KEY (mgr_id) REFERENCES 担当者マスタ(担当者id) ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE "売上データ" ADD CONSTRAINT fk_shohin FOREIGN KEY (商品id) REFERENCES 商品マスタ(商品id) ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE "売上データ" ADD CONSTRAINT fk_tanto FOREIGN KEY (担当者id) REFERENCES 担当者マスタ(担当者id) ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE "売上データ" ADD CONSTRAINT fk_kokyaku FOREIGN KEY (顧客id) REFERENCES 顧客マスタ(顧客id) ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;
ALTER TABLE "支店担当者マスタ" ADD CONSTRAINT fk_siten_mgr FOREIGN KEY (mgr_id) REFERENCES 支店担当者マスタ(支店担当者id) ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE;
   
END TRANSACTION;