· 7 years ago · Nov 06, 2018, 02:44 PM
1/*==============================================================*/
2/* DBMS name: SAP SQL Anywhere 17 */
3/* Created on: 11/6/2018 4:39:49 PM */
4/*==============================================================*/
5
6
7if exists(select 1 from sys.sysforeignkey where role='FK_PARDAVIM_RELATIONS_PARDAVEJ') then
8 alter table PARDAVIMAI
9 delete foreign key FK_PARDAVIM_RELATIONS_PARDAVEJ
10end if;
11
12if exists(select 1 from sys.sysforeignkey where role='FK_PARDAVIM_RELATIONS_PIRKEJAS') then
13 alter table PARDAVIMAI
14 delete foreign key FK_PARDAVIM_RELATIONS_PIRKEJAS
15end if;
16
17if exists(select 1 from sys.sysforeignkey where role='FK_PARDAVIM_RELATIONS_PREKE') then
18 alter table PARDAVIMAI
19 delete foreign key FK_PARDAVIM_RELATIONS_PREKE
20end if;
21
22drop index if exists PARDAVEJAS.PARDAVEJAS_PK;
23
24drop table if exists PARDAVEJAS;
25
26drop index if exists PARDAVIMAI.RELATIONSHIP_3_FK;
27
28drop index if exists PARDAVIMAI.RELATIONSHIP_2_FK;
29
30drop index if exists PARDAVIMAI.RELATIONSHIP_1_FK;
31
32drop index if exists PARDAVIMAI.PARDAVIMAI_PK;
33
34drop table if exists PARDAVIMAI;
35
36drop index if exists PIRKEJAS.PIRKEJAS_PK;
37
38drop table if exists PIRKEJAS;
39
40drop index if exists PREKE.PREKE_PK;
41
42drop table if exists PREKE;
43
44/*==============================================================*/
45/* Table: PARDAVEJAS */
46/*==============================================================*/
47create or replace table PARDAVEJAS
48(
49 PARD_ID numeric(6) not null,
50 PARD_VARDAS varchar(20) not null,
51 PARD_PAVARDE varchar(20) not null,
52 PARD_AK numeric(9) not null,
53 constraint PK_PARDAVEJAS primary key (PARD_ID)
54);
55
56/*==============================================================*/
57/* Index: PARDAVEJAS_PK */
58/*==============================================================*/
59create unique index PARDAVEJAS_PK on PARDAVEJAS (
60PARD_ID ASC
61);
62
63/*==============================================================*/
64/* Table: PARDAVIMAI */
65/*==============================================================*/
66create or replace table PARDAVIMAI
67(
68 PARDAV_ID numeric(9) not null,
69 PARD_ID numeric(6) null,
70 PIRK_ID numeric(6) null,
71 PREK_ID numeric(6) null,
72 PARDAV_KIEKIS numeric(9) not null,
73 constraint PK_PARDAVIMAI primary key (PARDAV_ID)
74);
75
76/*==============================================================*/
77/* Index: PARDAVIMAI_PK */
78/*==============================================================*/
79create unique index PARDAVIMAI_PK on PARDAVIMAI (
80PARDAV_ID ASC
81);
82
83/*==============================================================*/
84/* Index: RELATIONSHIP_1_FK */
85/*==============================================================*/
86create index RELATIONSHIP_1_FK on PARDAVIMAI (
87PARD_ID ASC
88);
89
90/*==============================================================*/
91/* Index: RELATIONSHIP_2_FK */
92/*==============================================================*/
93create index RELATIONSHIP_2_FK on PARDAVIMAI (
94PIRK_ID ASC
95);
96
97/*==============================================================*/
98/* Index: RELATIONSHIP_3_FK */
99/*==============================================================*/
100create index RELATIONSHIP_3_FK on PARDAVIMAI (
101PREK_ID ASC
102);
103
104/*==============================================================*/
105/* Table: PIRKEJAS */
106/*==============================================================*/
107create or replace table PIRKEJAS
108(
109 PIRK_ID numeric(6) not null,
110 PIRK_VARDAS varchar(20) not null,
111 PIRK_PAVARDE varchar(20) null,
112 PIRK_EMAIL varchar(30) null,
113 PIRK_TEL numeric(10) null,
114 PIRK_AK numeric(9) null,
115 constraint PK_PIRKEJAS primary key (PIRK_ID)
116);
117
118/*==============================================================*/
119/* Index: PIRKEJAS_PK */
120/*==============================================================*/
121create unique index PIRKEJAS_PK on PIRKEJAS (
122PIRK_ID ASC
123);
124
125/*==============================================================*/
126/* Table: PREKE */
127/*==============================================================*/
128create or replace table PREKE
129(
130 PREK_ID numeric(6) not null,
131 PREKE_PAVAD char(40) not null,
132 PREKE_APRAS varchar(255) null,
133 PREKE_KAINA decimal(9,2) not null,
134 constraint PK_PREKE primary key (PREK_ID)
135);
136
137/*==============================================================*/
138/* Index: PREKE_PK */
139/*==============================================================*/
140create unique index PREKE_PK on PREKE (
141PREK_ID ASC
142);
143
144alter table PARDAVIMAI
145 add constraint FK_PARDAVIM_RELATIONS_PARDAVEJ foreign key (PARD_ID)
146 references PARDAVEJAS (PARD_ID)
147 on update restrict
148 on delete restrict;
149
150alter table PARDAVIMAI
151 add constraint FK_PARDAVIM_RELATIONS_PIRKEJAS foreign key (PIRK_ID)
152 references PIRKEJAS (PIRK_ID)
153 on update restrict
154 on delete restrict;
155
156alter table PARDAVIMAI
157 add constraint FK_PARDAVIM_RELATIONS_PREKE foreign key (PREK_ID)
158 references PREKE (PREK_ID)
159 on update restrict
160 on delete restrict;