Professional Documents
Culture Documents
Advanced SQL I.1 Create Tables - SQL
Advanced SQL I.1 Create Tables - SQL
-- Database structure
--Location
create sequence Z_LOCATION_ID_SEQ;
--LPN
create sequence Z_LPN_ID_SEQ;
--LPN Lock
create table Z_LOCK
( LOCK_CODE char(2) primary key
, PRIORITY number(2) not null
);
--Item set
create table Z_ITEM_SET_DETAIL
( ITEM_ID integer not null
, DETAIL_ITEM_ID integer not null
, QUANTITY number default 1 not null check(QUANTITY >
0)
);
------------------
-- Input tables --
------------------
create sequence Z_INPT_ID_SEQ;
--Item
create table Z_INPT_ITEM
( INPT_ID integer /*default
Z_INPT_ID_SEQ.nextval*/ primary key
, REFERENCE varchar2(20)
not null
, DESCRIPTION varchar2(50) -- null means deletion
of the item
);
--LPN
create table Z_INPT_LPN_DETAIL
( INPT_ID integer /*default Z_INPT_ID_SEQ.nextval*/
primary key
, LPN_NUMBER varchar2(20)
not null
, ITEM_REFERENCE varchar2(20)
not null
, QUANTITY number
);
--Pallet
create table Z_INPT_PLT
( INPT_ID integer /*default Z_INPT_ID_SEQ.nextval*/
primary key
, PLT_NUMBER varchar2(20)
, LPN_NUMBER varchar2(20)
not null
);
--Item set
create table Z_INPT_ITEM_SET_DETAIL
( INPT_ID integer /*default
Z_INPT_ID_SEQ.nextval*/ primary key
, REFERENCE varchar2(20)
not null
, DETAIL_REFERENCE varchar2(20)
not null
, QUANTITY number
);
-- LPN lock
create table Z_INPT_LPN_LOCK
( INPT_ID integer /*default Z_INPT_ID_SEQ.nextval*/
primary key
, LPN_NUMBER varchar2(20)
not null
, LOCK_CODE char(2)
);
-- Also create bridge error logging tables for each active table (tables Z_* ->
Z_ERR_*)
begin
for t in (select TABLE_NAME from USER_TABLES where TABLE_NAME like 'Z\_%'
escape '\' and TABLE_NAME not like 'Z\_ERR\_%' escape '\' and TABLE_NAME not like
'Z\_INPT\_%' escape '\')
loop
DBMS_ERRLOG.CREATE_ERROR_LOG(t.TABLE_NAME, 'Z_ERR_' ||
substr(t.TABLE_NAME, 3, 24));
end loop;
end;
/