----------------------------------------
-- Exported tables from Finnish TARIC --
----------------------------------------

-- droping existing tables
--------------------------
if OBJECT_ID('dbo.c_chapt_note') is not null	drop table dbo.c_chapt_note;
if OBJECT_ID('dbo.c_meas_duty') is not null	drop table dbo.c_meas_duty;
if OBJECT_ID('dbo.c_meas_pref') is not null	drop table dbo.c_meas_pref;
if OBJECT_ID('dbo.c_preference') is not null	drop table dbo.c_preference;

if OBJECT_ID('dbo.t_10005') is not null drop table dbo.t_10005
if OBJECT_ID('dbo.t_11005') is not null drop table dbo.t_11005
if OBJECT_ID('dbo.t_12005') is not null drop table dbo.t_12005
if OBJECT_ID('dbo.t_14005') is not null drop table dbo.t_14005
if OBJECT_ID('dbo.t_15005') is not null drop table dbo.t_15005
if OBJECT_ID('dbo.t_16005') is not null drop table dbo.t_16005
if OBJECT_ID('dbo.t_17000') is not null drop table dbo.t_17000
if OBJECT_ID('dbo.t_20010') is not null drop table dbo.t_20010
if OBJECT_ID('dbo.t_20510') is not null drop table dbo.t_20510
if OBJECT_ID('dbo.t_21005') is not null drop table dbo.t_21005
if OBJECT_ID('dbo.t_21505') is not null drop table dbo.t_21505
if OBJECT_ID('dbo.t_22505') is not null drop table dbo.t_22505
if OBJECT_ID('dbo.t_23005') is not null drop table dbo.t_23005
if OBJECT_ID('dbo.t_23505') is not null drop table dbo.t_23505
if OBJECT_ID('dbo.t_24510') is not null drop table dbo.t_24510
if OBJECT_ID('dbo.t_24515') is not null drop table dbo.t_24515
if OBJECT_ID('dbo.t_25010') is not null drop table dbo.t_25010
if OBJECT_ID('dbo.t_25015') is not null drop table dbo.t_25015
if OBJECT_ID('dbo.t_27005') is not null drop table dbo.t_27005
if OBJECT_ID('dbo.t_29000') is not null drop table dbo.t_29000
if OBJECT_ID('dbo.t_29505') is not null drop table dbo.t_29505
if OBJECT_ID('dbo.t_30005') is not null drop table dbo.t_30005
if OBJECT_ID('dbo.t_30500') is not null drop table dbo.t_30500
if OBJECT_ID('dbo.t_35005') is not null drop table dbo.t_35005
if OBJECT_ID('dbo.t_35505') is not null drop table dbo.t_35505
if OBJECT_ID('dbo.t_36015') is not null drop table dbo.t_36015
if OBJECT_ID('dbo.t_37005') is not null drop table dbo.t_37005
if OBJECT_ID('dbo.t_37010') is not null drop table dbo.t_37010
if OBJECT_ID('dbo.t_37015') is not null drop table dbo.t_37015
if OBJECT_ID('dbo.t_37020') is not null drop table dbo.t_37020
if OBJECT_ID('dbo.t_38000') is not null drop table dbo.t_38000
if OBJECT_ID('dbo.t_40005') is not null drop table dbo.t_40005
if OBJECT_ID('dbo.t_40015') is not null drop table dbo.t_40015
if OBJECT_ID('dbo.t_40020') is not null drop table dbo.t_40020
if OBJECT_ID('dbo.t_40025') is not null drop table dbo.t_40025
if OBJECT_ID('dbo.t_41005') is not null drop table dbo.t_41005
if OBJECT_ID('dbo.t_41015') is not null drop table dbo.t_41015
if OBJECT_ID('dbo.t_41020') is not null drop table dbo.t_41020
if OBJECT_ID('dbo.t_43005') is not null drop table dbo.t_43005
if OBJECT_ID('dbo.t_43011') is not null drop table dbo.t_43011
if OBJECT_ID('dbo.t_43015') is not null drop table dbo.t_43015
if OBJECT_ID('dbo.t_43020') is not null drop table dbo.t_43020
if OBJECT_ID('dbo.t_43025') is not null drop table dbo.t_43025
if OBJECT_ID('dbo.t_13000') is not null drop table dbo.t_13000
if OBJECT_ID('dbo.t_20005') is not null drop table dbo.t_20005
if OBJECT_ID('dbo.t_20505') is not null drop table dbo.t_20505
if OBJECT_ID('dbo.t_23000') is not null drop table dbo.t_23000
if OBJECT_ID('dbo.t_24505') is not null drop table dbo.t_24505
if OBJECT_ID('dbo.t_25005') is not null drop table dbo.t_25005
if OBJECT_ID('dbo.t_27000') is not null drop table dbo.t_27000
if OBJECT_ID('dbo.t_28500') is not null drop table dbo.t_28500
if OBJECT_ID('dbo.t_29500') is not null drop table dbo.t_29500
if OBJECT_ID('dbo.t_30000') is not null drop table dbo.t_30000
if OBJECT_ID('dbo.t_36010') is not null drop table dbo.t_36010
if OBJECT_ID('dbo.t_37000') is not null drop table dbo.t_37000
if OBJECT_ID('dbo.t_40010') is not null drop table dbo.t_40010
if OBJECT_ID('dbo.t_41010') is not null drop table dbo.t_41010
if OBJECT_ID('dbo.t_43010') is not null drop table dbo.t_43010
if OBJECT_ID('dbo.t_15000') is not null drop table dbo.t_15000
if OBJECT_ID('dbo.t_20000') is not null drop table dbo.t_20000
if OBJECT_ID('dbo.t_20500') is not null drop table dbo.t_20500
if OBJECT_ID('dbo.t_21000') is not null drop table dbo.t_21000
if OBJECT_ID('dbo.t_21500') is not null drop table dbo.t_21500
if OBJECT_ID('dbo.t_22500') is not null drop table dbo.t_22500
if OBJECT_ID('dbo.t_24500') is not null drop table dbo.t_24500
if OBJECT_ID('dbo.t_27500') is not null drop table dbo.t_27500
if OBJECT_ID('dbo.t_28000') is not null drop table dbo.t_28000
if OBJECT_ID('dbo.t_35000') is not null drop table dbo.t_35000
if OBJECT_ID('dbo.t_35500') is not null drop table dbo.t_35500
if OBJECT_ID('dbo.t_36000') is not null drop table dbo.t_36000
if OBJECT_ID('dbo.t_43000') is not null drop table dbo.t_43000
if OBJECT_ID('dbo.t_10000') is not null drop table dbo.t_10000
if OBJECT_ID('dbo.t_11000') is not null drop table dbo.t_11000
if OBJECT_ID('dbo.t_16000') is not null drop table dbo.t_16000
if OBJECT_ID('dbo.t_23500') is not null drop table dbo.t_23500
if OBJECT_ID('dbo.t_25000') is not null drop table dbo.t_25000
if OBJECT_ID('dbo.t_41000') is not null drop table dbo.t_41000
if OBJECT_ID('dbo.t_12000') is not null drop table dbo.t_12000
if OBJECT_ID('dbo.t_14000') is not null drop table dbo.t_14000
if OBJECT_ID('dbo.t_40000') is not null drop table dbo.t_40000


SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_PADDING ON
GO

-- EU part of TARIC
-------------------

-- footnote.type
create table dbo.t_10000 
		(footn_typ_id char(3) not null, -- footnote.type.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		appl_cod char(1) not null, -- application.code
		 constraint PK_10000 primary key clustered (footn_typ_id asc));

-- footnote.type.description
create table dbo.t_10005 
		(footn_typ_id char(3) not null, -- footnote.type.id
		lang_id char(2) not null, -- language.id
		footn_typ_descr nvarchar(500)  null, -- description
		 constraint PK_10005 primary key clustered (footn_typ_id asc, lang_id asc));

-- certificate.type
create table dbo.t_11000 
		(cert_typ_cod_id char(1) not null, -- certificate.type.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_11000 primary key clustered (cert_typ_cod_id asc));

-- certificate.type.description
create table dbo.t_11005 
		(cert_typ_cod_id char(1) not null, -- certificate.type.code
		lang_id char(2) not null, -- language.id
		cert_typ_descr nvarchar(500)  null, -- description
		 constraint PK_11005 primary key clustered (cert_typ_cod_id asc, lang_id asc));

-- additional.code.type
create table dbo.t_12000 
		(add_cod_typ_id char(1) not null, -- additional.code.type.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		appl_cod char(1) not null, -- application.code
		meurs_tabl_plan_id char(2)  null, -- meursing.table.plan.id
		 constraint PK_12000 primary key clustered (add_cod_typ_id asc));

-- additional.code.type.description
create table dbo.t_12005 
		(add_cod_typ_id char(1) not null, -- additional.code.type.id
		lang_id char(2) not null, -- language.id
		add_cod_typ_descr nvarchar(500)  null, -- description
		 constraint PK_12005 primary key clustered (add_cod_typ_id asc, lang_id asc));

-- measure.type.series
create table dbo.t_14000 
		(meas_typ_ser_id char(2) not null, -- measure.type.series.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		meas_typ_comb_cod char(1) not null, -- measure.type.combination
		 constraint PK_14000 primary key clustered (meas_typ_ser_id asc));

-- measure.type.series.description
create table dbo.t_14005 
		(meas_typ_ser_id char(2) not null, -- measure.type.series.id
		lang_id char(2) not null, -- language.id
		meas_typ_ser_descr nvarchar(500)  null, -- description
		 constraint PK_14005 primary key clustered (meas_typ_ser_id asc, lang_id asc));

-- regulation.group
create table dbo.t_15000 
		(regi_id char(3) not null, -- regulation.group.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_15000 primary key clustered (regi_id asc));

-- regulation.group.description
create table dbo.t_15005 
		(regi_id char(3) not null, -- regulation.group.id
		lang_id char(2) not null, -- language.id
		regi_descr nvarchar(500)  null, -- description
		 constraint PK_15005 primary key clustered (regi_id asc, lang_id asc));

-- regulation.role.type
create table dbo.t_16000 
		(rol_typ_id char(1) not null, -- regulation.role.type.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_16000 primary key clustered (rol_typ_id asc));

-- regulation.role.type.description
create table dbo.t_16005 
		(rol_typ_id char(1) not null, -- regulation.role.type.id
		lang_id char(2) not null, -- language.id
		reg_rol_descr nvarchar(500)  null, -- description
		 constraint PK_16005 primary key clustered (rol_typ_id asc, lang_id asc));

-- publication.sigle
create table dbo.t_17000 
		(code_type_id char(4) not null, -- code.type.id
		code char(10) not null, -- code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		publication_code char(1) not null, -- publication.code
		publication_sigle nvarchar(25)  null, -- publication.sigle
		 constraint PK_17000 primary key clustered (code_type_id asc, code asc, dat_start asc));

-- footnote
create table dbo.t_20000 
		(footn_typ_id char(3) not null, -- footnote.type.id
		footn_id char(5) not null, -- footnote.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_20000 primary key clustered (footn_typ_id asc, footn_id asc));

-- footnote.description.period
create table dbo.t_20005 
		(descr_per_footn_sid int identity(-1, -1) not null, -- footnote.description.period.sid
		footn_typ_id char(3) not null, -- footnote.type.id
		footn_id char(5) not null, -- footnote.id
		dat_start date not null, -- validity.start.date
		 constraint PK_20005 primary key clustered (descr_per_footn_sid asc));

-- footnote.description
create table dbo.t_20010 
		(descr_per_footn_sid int not null, -- footnote.description.period.sid
		lang_id char(2) not null, -- language.id
		footn_typ_id char(3) not null, -- footnote.type.id
		footn_id char(5) not null, -- footnote.id
		long_descr nvarchar(max)  null, -- description
		 constraint PK_20010 primary key clustered (descr_per_footn_sid asc, lang_id asc));

-- certificate
create table dbo.t_20500 
		(cert_typ_cod_id char(1) not null, -- certificate.type.code
		cert_ref_no char(3) not null, -- certificate.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_20500 primary key clustered (cert_typ_cod_id asc, cert_ref_no asc));

-- certificate.description.period
create table dbo.t_20505 
		(cert_descr_sid int identity(-1, -1) not null, -- certificate.description.period.sid
		cert_typ_cod_id char(1) not null, -- certificate.type.code
		cert_ref_no char(3) not null, -- certificate.code
		dat_start date not null, -- validity.start.date
		 constraint PK_20505 primary key clustered (cert_descr_sid asc));

-- certificate.description
create table dbo.t_20510 
		(cert_descr_sid int not null, -- certificate.description.period.sid
		lang_id char(2) not null, -- language.id
		cert_typ_cod_id char(1) not null, -- certificate.type.code
		cert_ref_no char(3) not null, -- certificate.code
		cert_typ_cod_descr nvarchar(500)  null, -- description
		 constraint PK_20510 primary key clustered (cert_descr_sid asc, lang_id asc));

-- measurement.unit
create table dbo.t_21000 
		(meas_unit_cod_id char(3) not null, -- measurement.unit.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_21000 primary key clustered (meas_unit_cod_id asc));

-- measurement.unit.description
create table dbo.t_21005 
		(meas_unit_cod_id char(3) not null, -- measurement.unit.code
		lang_id char(2) not null, -- language.id
		meas_unit_cod_descr nvarchar(500)  null, -- description
		 constraint PK_21005 primary key clustered (meas_unit_cod_id asc, lang_id asc));

-- measurement.unit.qualifier
create table dbo.t_21500 
		(meas_unit_qual_cod_id char(1) not null, -- measurement.unit.qualifier.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_21500 primary key clustered (meas_unit_qual_cod_id asc));

-- measurement.unit.qualifier.description
create table dbo.t_21505 
		(meas_unit_qual_cod_id char(1) not null, -- measurement.unit.qualifier.code
		lang_id char(2) not null, -- language.id
		meas_unit_qual_cod_descr nvarchar(500)  null, -- description
		 constraint PK_21505 primary key clustered (meas_unit_qual_cod_id asc, lang_id asc));

-- monetary.unit
create table dbo.t_22500 
		(mon_unit_cod_id char(3) not null, -- monetary.unit.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_22500 primary key clustered (mon_unit_cod_id asc));

-- monetary.unit.description
create table dbo.t_22505 
		(mon_unit_cod_id char(3) not null, -- monetary.unit.code
		lang_id char(2) not null, -- language.id
		mon_unit_cod_descr nvarchar(500)  null, -- description
		 constraint PK_22505 primary key clustered (mon_unit_cod_id asc, lang_id asc));

-- duty.expression
create table dbo.t_23000 
		(duty_expr_id char(2) not null, -- duty.expression.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		duty_amo_appl_cod char(1) not null, -- duty.amount.applicability.code
		meas_unit_appl_cod char(1) not null, -- measurement.unit.applicability.code
		mon_unit_appl_cod char(1) not null, -- monetary.unit.applicability.code
		 constraint PK_23000 primary key clustered (duty_expr_id asc));

-- duty.expression.description
create table dbo.t_23005 
		(duty_expr_id char(2) not null, -- duty.expression.id
		lang_id char(2) not null, -- language.id
		duty_expr_descr nvarchar(500)  null, -- description
		 constraint PK_23005 primary key clustered (duty_expr_id asc, lang_id asc));

-- measure.type
create table dbo.t_23500 
		(meas_typ_id char(6) not null, -- measure.type.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		trad_mov_cod char(1) not null, -- trade.movement.code
		prior_cod char(1) not null, -- priority.code
		meas_comp_appl_cod char(1) not null, -- measure.component.applicable.code
		orig_dest_cod char(1) not null, -- origin.dest.code
		ord_numb_capt_cod char(1) not null, -- order.number.capture.code
		expl_lev char(2) not null, -- measure.explosion.level
		meas_typ_ser_id char(2) not null, -- measure.type.series.id
		 constraint PK_23500 primary key clustered (meas_typ_id asc));

-- measure.type.description
create table dbo.t_23505 
		(meas_typ_id char(6) not null, -- measure.type.id
		lang_id char(2) not null, -- language.id
		meas_typ_descr nvarchar(500)  null, -- description
		 constraint PK_23505 primary key clustered (meas_typ_id asc, lang_id asc));

-- additional.code
create table dbo.t_24500 
		(add_cod_sid int identity(-1, -1) not null, -- additional.code.sid
		add_cod_typ_id char(1) not null, -- additional.code.type.id
		add_cod char(3) not null, -- additional.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_24500 primary key clustered (add_cod_sid asc));

-- additional.code.description.period
create table dbo.t_24505 
		(add_cod_descr_sid int identity(-1, -1) not null, -- additional.code.description.period.sid
		add_cod_sid int not null, -- additional.code.sid
		add_cod_typ_id char(1) not null, -- additional.code.type.id
		add_cod char(3) not null, -- additional.code
		dat_start date not null, -- validity.start.date
		 constraint PK_24505 primary key clustered (add_cod_descr_sid asc));

-- additional.code.description
create table dbo.t_24510 
		(add_cod_descr_sid int not null, -- additional.code.description.period.sid
		lang_id char(2) not null, -- language.id
		add_cod_sid int not null, -- additional.code.sid
		add_cod_typ_id char(1) not null, -- additional.code.type.id
		add_cod char(3) not null, -- additional.code
		long_descr nvarchar(max)  null, -- description
		 constraint PK_24510 primary key clustered (add_cod_descr_sid asc, lang_id asc));

-- footnote.association.additional.code
create table dbo.t_24515 
		(add_cod_sid int not null, -- additional.code.sid
		footn_typ_id char(3) not null, -- footnote.type.id
		footn_id char(5) not null, -- footnote.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		add_cod_typ_id char(1) not null, -- additional.code.type.id
		add_cod char(3) not null, -- additional.code
		 constraint PK_24515 primary key clustered (add_cod_sid asc, footn_typ_id asc, footn_id asc, dat_start asc));

-- geographical.area
create table dbo.t_25000 
		(geo_area_sid int identity(-1, -1) not null, -- geographical.area.sid
		geo_area_id char(4) not null, -- geographical.area.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		geo_area_code int not null, -- geographical.code
		par_geo_area_sid int  null, -- parent.geographical.area.group.sid
		 constraint PK_25000 primary key clustered (geo_area_sid asc));

-- geographical.area.description.period
create table dbo.t_25005 
		(geo_area_descr_sid int identity(-1, -1) not null, -- geographical.area.description.period.sid
		geo_area_sid int not null, -- geographical.area.sid
		dat_start date not null, -- validity.start.date
		geo_area_id char(4) not null, -- geographical.area.id
		 constraint PK_25005 primary key clustered (geo_area_descr_sid asc));

-- geographical.area.description
create table dbo.t_25010 
		(geo_area_descr_sid int not null, -- geographical.area.description.period.sid
		lang_id char(2) not null, -- language.id
		geo_area_sid int not null, -- geographical.area.sid
		geo_area_id char(4) not null, -- geographical.area.id
		geo_area_descr nvarchar(500)  null, -- description
		 constraint PK_25010 primary key clustered (geo_area_descr_sid asc, lang_id asc));

-- geographical.area.membership
create table dbo.t_25015 
		(geo_area_sid int not null, -- geographical.area.sid
		geo_area_group_sid int not null, -- geographical.area.group.sid
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_25015 primary key clustered (geo_area_sid asc, geo_area_group_sid asc, dat_start asc));

-- goods.nomenclature.group
create table dbo.t_27000 
		(nom_gro_typ char(1) not null, -- goods.nomenclature.group.type
		goods_nom_gro_id char(6) not null, -- goods.nomenclature.group.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		nom_gro_fac_cod char(1) not null, -- nomenclature.group.facility.code
		 constraint PK_27000 primary key clustered (nom_gro_typ asc, goods_nom_gro_id asc));

-- goods.nomenclature.group.description
create table dbo.t_27005 
		(nom_gro_typ char(1) not null, -- goods.nomenclature.group.type
		goods_nom_gro_id char(6) not null, -- goods.nomenclature.group.id
		lang_id char(2) not null, -- language.id
		goods_nom_gro_descr nvarchar(500)  null, -- description
		 constraint PK_27005 primary key clustered (nom_gro_typ asc, goods_nom_gro_id asc, lang_id asc));

-- complete.abrogation.regulation
create table dbo.t_27500 
		(com_abr_rol_typ_id char(1) not null, -- complete.abrogation.regulation.role
		com_abr_reg_id char(8) not null, -- complete.abrogation.regulation.id
		date_com date  null, -- published.date
		off_journ_id char(5)  null, -- officialjournal.number
		off_journ_pag char(4)  null, -- officialjournal.page
		repl_ind char(1) not null, -- replacement.indicator
		com_abr_reg_text nvarchar(500)  null, -- information.text
		appr_flag char(1) not null, -- approved.flag
		 constraint PK_27500 primary key clustered (com_abr_rol_typ_id asc, com_abr_reg_id asc));

-- explicit.abrogation.regulation
create table dbo.t_28000 
		(abr_rol_typ_id char(1) not null, -- explicit.abrogation.regulation.role
		abr_reg_id char(8) not null, -- explicit.abrogation.regulation.id
		date_exp date  null, -- published.date
		off_journ_id char(5)  null, -- officialjournal.number
		off_journ_pag char(4)  null, -- officialjournal.page
		repl_ind char(1) not null, -- replacement.indicator
		date_abr date not null, -- abrogation.date
		abr_reg_text nvarchar(500)  null, -- information.text
		appr_flag char(1) not null, -- approved.flag
		 constraint PK_28000 primary key clustered (abr_rol_typ_id asc, abr_reg_id asc));

-- base.regulation
create table dbo.t_28500 
		(bas_rol_typ_id char(1) not null, -- base.regulation.role
		bas_reg_id char(8) not null, -- base.regulation.id
		date_rol date  null, -- published.date
		off_journ_id char(5)  null, -- officialjournal.number
		off_journ_pag char(4)  null, -- officialjournal.page
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		date_rol_end date  null, -- effective.end.date
		comm_cod char(1) not null, -- community.code
		regi_id char(3) not null, -- regulation.group.id
		ant_dump_rol_typ_id char(1)  null, -- antidumping.regulation.role
		ant_dump_reg_id char(8)  null, -- related.antidumping.regulation.id
		com_abr_rol_typ_id char(1)  null, -- complete.abrogation.regulation.role
		com_abr_reg_id char(8)  null, -- complete.abrogation.regulation.id
		abr_rol_typ_id char(1)  null, -- explicit.abrogation.regulation.role
		abr_reg_id char(8)  null, -- explicit.abrogation.regulation.id
		den_repl_ind char(1) not null, -- replacement.indicator
		den_stopp_flag char(1) not null, -- stopped.flag
		bas_reg_text nvarchar(500)  null, -- information.text
		appr_flag char(1) not null, -- approved.flag
		 constraint PK_28500 primary key clustered (bas_rol_typ_id asc, bas_reg_id asc));

-- modification.regulation
create table dbo.t_29000 
		(mod_bas_rol_typ_id char(1) not null, -- modification.regulation.role
		mod_bas_reg_id char(8) not null, -- modification.regulation.id
		date_mod date  null, -- published.date
		off_journ_id char(5)  null, -- officialjournal.number
		off_journ_pag char(4)  null, -- officialjournal.page
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		date_mod_end date  null, -- effective.end.date
		bas_rol_typ_id char(1) not null, -- base.regulation.role
		bas_reg_id char(8) not null, -- base.regulation.id
		com_abr_rol_typ_id char(1)  null, -- complete.abrogation.regulation.role
		com_abr_reg_id char(8)  null, -- complete.abrogation.regulation.id
		abr_rol_typ_id char(1)  null, -- explicit.abrogation.regulation.role
		abr_reg_id char(8)  null, -- explicit.abrogation.regulation.id
		repl_ind char(1) not null, -- replacement.indicator
		den_stopp_flag char(1) not null, -- stopped.flag
		mod_bas_reg_text nvarchar(500)  null, -- information.text
		appr_flag char(1) not null, -- approved.flag
		 constraint PK_29000 primary key clustered (mod_bas_rol_typ_id asc, mod_bas_reg_id asc));

-- prorogation.regulation
create table dbo.t_29500 
		(pror_rol_typ_id char(1) not null, -- prorogation.regulation.role
		pror_rol_reg_id char(8) not null, -- prorogation.regulation.id
		date_rol date  null, -- published.date
		off_journ_id char(5)  null, -- officialjournal.number
		off_journ_pag char(4)  null, -- officialjournal.page
		repl_ind char(1) not null, -- replacement.indicator
		pror_rol_reg_text nvarchar(500)  null, -- information.text
		appr_flag char(1) not null, -- approved.flag
		 constraint PK_29500 primary key clustered (pror_rol_typ_id asc, pror_rol_reg_id asc));

-- prorogation.regulation.action
create table dbo.t_29505 
		(pror_rol_typ_id char(1) not null, -- prorogation.regulation.role
		pror_rol_reg_id char(8) not null, -- prorogation.regulation.id
		bas_rol_typ_id char(1) not null, -- prorogated.regulation.role
		bas_reg_id char(8) not null, -- prorogated.regulation.id
		date_rol date  null, -- prorogated.date
		 constraint PK_29505 primary key clustered (pror_rol_typ_id asc, pror_rol_reg_id asc, bas_rol_typ_id asc, bas_reg_id asc));

-- full.temporary.stop.regulation
create table dbo.t_30000 
		(fts_rol_typ_id char(1) not null, -- full.temporary.stop.regulation.role
		fts_int_rol_reg_id char(8) not null, -- full.temporary.stop.regulation.id
		date_rol date  null, -- published.date
		off_journ_id char(5)  null, -- officialjournal.number
		off_journ_pag char(4)  null, -- officialjournal.page
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		date_rol_end date  null, -- effective.enddate
		com_abr_rol_typ_id char(1)  null, -- complete.abrogation.regulation.role
		com_abr_reg_id char(8)  null, -- complete.abrogation.regulation.id
		abr_rol_typ_id char(1)  null, -- explicit.abrogation.regulation.role
		abr_reg_id char(8)  null, -- explicit.abrogation.regulation.id
		repl_ind char(1) not null, -- replacement.indicator
		fts_rol_typ_text nvarchar(500)  null, -- information.text
		appr_flag char(1) not null, -- approved.flag
		 constraint PK_30000 primary key clustered (fts_rol_typ_id asc, fts_int_rol_reg_id asc));

-- fts.regulation.action
create table dbo.t_30005 
		(fts_rol_typ_id char(1) not null, -- fts.regulation.role
		fts_int_rol_reg_id char(8) not null, -- fts.regulation.id
		bas_rol_typ_id char(1) not null, -- stopped.regulation.role
		mod_bas_reg_id char(8) not null, -- stopped.regulation.id
		 constraint PK_30005 primary key clustered (fts_rol_typ_id asc, fts_int_rol_reg_id asc, bas_rol_typ_id asc, mod_bas_reg_id asc));

-- regulation.replacement
create table dbo.t_30500 
		(replacing_rol_typ_id char(1) not null, -- replacing.regulation.role
		replacing_reg_id char(8) not null, -- replacing.regulation.id
		replaced_rol_typ_id char(1) not null, -- replaced.regulation.role
		replaced_reg_id char(8) not null, -- replaced.regulation.id
		meas_typ_id char(6)  null, -- measure.type.id
		geo_area_id char(4)  null, -- geographical.area.id
		chapt_head char(2)  null -- chapter.heading
		 );

-- measure.condition.code
create table dbo.t_35000 
		(meas_cond_cod_id char(2) not null, -- condition.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_35000 primary key clustered (meas_cond_cod_id asc));

-- measure.condition.code.description
create table dbo.t_35005 
		(meas_cond_cod_id char(2) not null, -- condition.code
		lang_id char(2) not null, -- language.id
		meas_cond_cod_descr nvarchar(500)  null, -- description
		 constraint PK_35005 primary key clustered (meas_cond_cod_id asc, lang_id asc));

-- measure.action
create table dbo.t_35500 
		(meas_act_cod_id char(3) not null, -- action.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_35500 primary key clustered (meas_act_cod_id asc));

-- measure.action.description
create table dbo.t_35505 
		(meas_act_cod_id char(3) not null, -- action.code
		lang_id char(2) not null, -- language.id
		meas_act_cod_descr nvarchar(500)  null, -- description
		 constraint PK_35505 primary key clustered (meas_act_cod_id asc, lang_id asc));

-- quota.order.number
create table dbo.t_36000 
		(quota_order_sid int not null, -- quota.order.number.sid
		quota_order_id char(6) not null, -- quota.order.number.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		 constraint PK_36000 primary key clustered (quota_order_sid asc));

-- quota.order.number.origin
create table dbo.t_36010 
		(quota_order_origin_sid int not null, -- quota.order.number.origin.sid
		quota_order_sid int not null, -- quota.order.number.sid
		geo_area_id char(4) not null, -- geographical.area.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		geo_area_sid int not null, -- geographical.area.sid
		 constraint PK_36010 primary key clustered (quota_order_origin_sid asc));

-- quota.order.number.origin.exclusions
create table dbo.t_36015 
		(quota_order_origin_sid int not null, -- quota.order.number.origin.sid
		excl_geo_area_sid int not null, -- excluded.geographical.area.sid
		 constraint PK_36015 primary key clustered (quota_order_origin_sid asc, excl_geo_area_sid asc));

-- quota.definition
create table dbo.t_37000 
		(quota_def_sid int not null, -- quota.definition.sid
		quota_order_id char(6) not null, -- quota.order.number.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		quota_order_sid int not null, -- quota.order.number.sid
		quota_amount decimal(14, 3) not null, -- volume
		quota_amount_init decimal(14, 3) not null, -- initial.volume
		mon_unit_cod_id char(3)  null, -- monetary.unit.code
		meas_unit_cod_id char(3)  null, -- measurement.unit.code
		meas_unit_qual_cod_id char(1)  null, -- measurement.unit.qualifier.code
		quota_max_precision tinyint not null, -- maximum.precision
		quota_critical_state_code char(1) not null, -- critical.state
		quota_critical_threshold smallint not null, -- critical.threshold
		short_desc nvarchar(500)  null, -- description
		 constraint PK_37000 primary key clustered (quota_def_sid asc));

-- quota.association
create table dbo.t_37005 
		(quota_def_main_sid int not null, -- main.quota.definition.sid
		quota_def_sub_sid int not null, -- sub.quota.definition.sid
		rel_type char(2) not null, -- relation.type
		coefficient decimal(16, 5)  null, -- coefficient
		 constraint PK_37005 primary key clustered (quota_def_main_sid asc, quota_def_sub_sid asc));

-- quota.blocking.period
create table dbo.t_37010 
		(block_period_sid int not null, -- quota.blocking.period.sid
		quota_def_sid int not null, -- quota.definition.sid
		dat_start date not null, -- blocking.start.date
		dat_end date not null, -- blocking.end.date
		period_type tinyint not null, -- blocking.period.type
		short_desc nvarchar(500)  null, -- description
		 constraint PK_37010 primary key clustered (block_period_sid asc));

-- quota.suspension.period
create table dbo.t_37015 
		(susp_period_def_sid int not null, -- quota.suspension.period.sid
		quota_def_sid int not null, -- quota.definition.sid
		dat_start date not null, -- suspension.start.date
		dat_end date not null, -- suspension.end.date
		short_desc nvarchar(500)  null, -- description
		 constraint PK_37015 primary key clustered (susp_period_def_sid asc));

-- quota.extended.information
create table dbo.t_37020 
		(quota_def_sid int not null, -- quota.definition.sid
		balance decimal(14, 3) not null, -- balance
		imported_amount decimal(14, 3) not null, -- imported.amount
		alloc_date date  null, -- last.allocation.date
		alloc_perc decimal(6, 3)  null, -- allocated.percentage
		import_date date  null, -- last.import.date
		exhaust_state char(1) not null, -- quota.exhaustion.state
		exhaust_date date  null, -- exhaustion.date
		blocked_state char(1) not null, -- quota.blocked.state
		suspended_state char(1) not null, -- quota.suspended.state
		total_alloc decimal(14, 3) not null, -- total.awaiting.allocation
		 constraint PK_37020 primary key clustered (quota_def_sid asc));

-- ceiling
create table dbo.t_38000 
		(surveillance char(6) not null, -- surveillance.number
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		dat_ceil_reach date not null, -- ceiling.reached.date
		 constraint PK_38000 primary key clustered (surveillance asc, dat_start asc));

-- goods.nomenclature
create table dbo.t_40000 
		(nom_item_sid int not null, -- goods.nomenclature.sid
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		prod_lin char(2) not null, -- producline.suffix
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		stat_lin_cod char(1) not null, -- statistical.indicator
		 constraint PK_40000 primary key clustered (nom_item_sid asc));

-- goods.nomenclature.indents
create table dbo.t_40005 
		(nom_item_ind_sid int not null, -- goods.nomenclature.indent.sid
		nom_item_sid int not null, -- goods.nomenclature.sid
		dat_start date not null, -- validity.start.date
		quant_ind char(2) not null, -- number.indents
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		prod_lin char(2) not null, -- productline.suffix
		 constraint PK_40005 primary key clustered (nom_item_ind_sid asc));

-- goods.nomenclature.description.period
create table dbo.t_40010 
		(descr_per_goods_nom_sid int not null, -- goods.nomenclature.description.period.sid
		nom_item_sid int not null, -- goods.nomenclature.sid
		dat_start date not null, -- validity.start.date
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		prod_lin char(2) not null, -- productline.suffix
		 constraint PK_40010 primary key clustered (descr_per_goods_nom_sid asc));

-- goods.nomenclature.description
create table dbo.t_40015 
		(descr_per_goods_nom_sid int not null, -- goods.nomenclature.description.period.sid
		lang_id char(2) not null, -- language.id
		nom_item_sid int not null, -- goods.nomenclature.sid
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		prod_lin char(2) not null, -- productline.suffix
		long_descr nvarchar(max)  null, -- description
		 constraint PK_40015 primary key clustered (descr_per_goods_nom_sid asc, lang_id asc));

-- footnote.association.goods.nomenclature
create table dbo.t_40020 
		(nom_item_sid int not null, -- goods.nomenclature.sid
		footn_typ_id char(3) not null, -- footnote.type
		footn_id char(5) not null, -- footnote.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		prod_lin char(2) not null, -- productline.suffix
		 constraint PK_40020 primary key clustered (nom_item_sid asc, footn_typ_id asc, footn_id asc, dat_start asc));

-- nomenclature.group.membership
create table dbo.t_40025 
		(nom_item_sid int not null, -- goods.nomenclature.sid
		nom_gro_typ char(1) not null, -- goods.nomenclature.group.type
		goods_nom_gro_id char(6) not null, -- goods.nomenclature.group.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		prod_lin char(2) not null, -- productline.suffix
		 constraint PK_40025 primary key clustered (nom_item_sid asc, nom_gro_typ asc, goods_nom_gro_id asc, dat_start asc));

-- export.refund.nomenclature
create table dbo.t_41000 
		(exp_ref_nom_item_sid int not null, -- export.refund.nomenclature.sid
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		add_cod_typ_id char(1) not null, -- additional.code.type
		add_cod char(3) not null, -- export.refund.code
		prod_lin char(2) not null, -- productline.suffix
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		nom_item_sid int not null, -- goods.nomenclature.sid
		 constraint PK_41000 primary key clustered (exp_ref_nom_item_sid asc));

-- export.refund.nomenclature.indents
create table dbo.t_41005 
		(exp_ref_nom_item_ind_sid int not null, -- export.refund.nomenclature.indents.sid
		exp_ref_nom_item_sid int not null, -- export.refund.nomenclature.sid
		dat_start date not null, -- validity.start.date
		quant_ind char(2) not null, -- number.export.refund.nomenclature.indents
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		add_cod_typ_id char(1) not null, -- additional.code.type
		add_cod char(3) not null, -- export.refund.code
		prod_lin char(2) not null, -- productline.suffix
		 constraint PK_41005 primary key clustered (exp_ref_nom_item_ind_sid asc));

-- export.refund.nomenclature.description.period
create table dbo.t_41010 
		(exp_ref_nom_item_sid_desc int not null, -- export.refund.nomenclature.description.period.sid
		exp_ref_nom_item_sid int not null, -- export.refund.nomenclature.sid
		dat_start date not null, -- validity.start.date
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		add_cod_typ_id char(1) not null, -- additional.code.type
		add_cod char(3) not null, -- export.refund.code
		prod_lin char(2) not null, -- productline.suffix
		 constraint PK_41010 primary key clustered (exp_ref_nom_item_sid_desc asc));

-- export.refund.nomenclature.description
create table dbo.t_41015 
		(exp_ref_nom_item_sid_desc int not null, -- export.refund.nomenclature.description.period.sid
		lang_id char(2) not null, -- language.id
		exp_ref_nom_item_sid int not null, -- export.refund.nomenclature.sid
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		add_cod_typ_id char(1) not null, -- additional.code.type
		add_cod char(3) not null, -- export.refund.code
		prod_lin char(2) not null, -- productline.suffix
		long_descr nvarchar(max)  null, -- description
		 constraint PK_41015 primary key clustered (exp_ref_nom_item_sid_desc asc, lang_id asc));

-- footnote.association.ern
create table dbo.t_41020 
		(exp_ref_nom_item_sid int not null, -- export.refund.nomenclature.sid
		footn_typ_id char(3) not null, -- footnote.type
		footn_id char(5) not null, -- footnote.id
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		goods_nom_item_id char(10) not null, -- goods.nomenclature.item.id
		add_cod_typ_id char(1) not null, -- additional.code.type
		add_cod char(3) not null, -- export.refund.code
		prod_lin char(2) not null, -- productline.suffix
		 constraint PK_41020 primary key clustered (exp_ref_nom_item_sid asc, footn_typ_id asc, footn_id asc, dat_start asc));

-- measure
create table dbo.t_43000 
		(meas_sid int identity(-1, -1) not null, -- measure.sid
		meas_typ_id char(6) not null, -- measure.type
		geo_area_id char(4) not null, -- geographical.area
		goods_nom_item_id char(10)  null, -- goods.nomenclature.item.id
		add_cod_typ_id char(1)  null, -- additional.code.type
		add_cod char(3)  null, -- additional.code
		ord_numb char(6)  null, -- ordernumber
		red_indicator char(1)  null, -- reduction.indicator
		dat_start date not null, -- validity.start.date
		rol_typ_id char(1) not null, -- measure.generating.regulation.role
		reg_id char(8) not null, -- measure.generating.regulation.id
		dat_end date  null, -- validity.end.date
		just_rol_typ_id char(1)  null, -- justification.regulation.role
		just_reg_id char(8)  null, -- justification.regulation.id
		stopped_flg char(1) not null, -- stopped.flag
		geo_area_sid int  null, -- geographical.area.sid
		nom_item_sid int  null, -- goods.nomenclature.sid
		add_cod_sid int  null, -- additional.code.sid
		exp_ref_nom_item_sid int  null, -- export.refund.nomenclature.sid
		 constraint PK_43000 primary key clustered (meas_sid asc));

-- measure.component
create table dbo.t_43005 
		(meas_sid int not null, -- measure.sid
		duty_expr_id char(2) not null, -- duty.expression.id
		duty_amo decimal(10, 3)  null, -- duty.amount
		mon_unit_cod char(3)  null, -- monetary.unit.code
		meas_unit char(3)  null, -- measurement.unit.code
		meas_unit_qual char(1)  null, -- measurement.unit.qualifier.code
		 constraint PK_43005 primary key clustered (meas_sid asc, duty_expr_id asc));

-- measure.condition
create table dbo.t_43010 
		(meas_cond_sid int identity(-1, -1) not null, -- measure.condition.sid
		meas_sid int not null, -- measure.sid
		cond_typ_cod char(2) not null, -- condition.code
		seq_numb smallint not null, -- component.sequence.number
		cond_amo decimal(10, 3)  null, -- condition.duty.amount
		cond_mon_unit char(3)  null, -- condition.monetary.unit.code
		cond_meas_unit char(3)  null, -- condition.measurement.unit.code
		cond_meas_unit_qual char(1)  null, -- condition.measurement.unit.qualifier.code
		act_cod char(3)  null, -- action.code
		cert_typ_cod_id char(1)  null, -- certificate.type.code
		cert_ref_no char(3)  null, -- certificate.code
		 constraint PK_43010 primary key clustered (meas_cond_sid asc));

-- measure.condition.component
create table dbo.t_43011 
		(meas_cond_sid int not null, -- measure.condition.sid
		duty_expr_id char(2) not null, -- duty.expression.id
		act_amo decimal(10, 3)  null, -- duty.amount
		act_mon_unit char(3)  null, -- monetary.unit.code
		act_meas_unit char(3)  null, -- measurement.unit.code
		act_meas_unit_qual char(1)  null, -- measurement.unit.qualifier.code
		 constraint PK_43011 primary key clustered (meas_cond_sid asc, duty_expr_id asc));

-- measure.excluded.geographical.area
create table dbo.t_43015 
		(meas_sid int not null, -- measure.sid
		geo_area_id char(4) not null, -- excluded.geographical.area
		geo_area_sid int not null, -- geographical.area.sid
		 constraint PK_43015 primary key clustered (meas_sid asc, geo_area_id asc));

-- footnote.association.measure
create table dbo.t_43020 
		(meas_sid int not null, -- measure.sid
		footn_typ_id char(3) not null, -- footnote.type.id
		footn_id char(5) not null, -- footnote.id
		 constraint PK_43020 primary key clustered (meas_sid asc, footn_typ_id asc, footn_id asc));

-- measure.partial.temporary.stop
create table dbo.t_43025 
		(meas_sid int not null, -- measure.sid
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		pts_reg_id char(8) not null, -- partial.temporary.stop.regulation.id
		off_journ_id char(5)  null, -- partial.temporary.stop.regulation.officialjournal.number
		off_journ_pag char(4)  null, -- partial.temporary.stop.regulation.officialjournal.page
		pts_abr_reg_id char(8)  null, -- abrogation.regulation.id
		abr_off_journ_id char(5)  null, -- abrogation.regulation.officialjournal.number
		abr_journ_pag char(4)  null, -- abrogation.regulation.officialjournal.page
		 constraint PK_43025 primary key clustered (meas_sid asc, dat_start asc));
GO

ALTER TABLE dbo.t_10005  WITH CHECK ADD  CONSTRAINT FK_10005_10000 FOREIGN KEY(footn_typ_id) REFERENCES dbo.t_10000 (footn_typ_id);

ALTER TABLE dbo.t_11005  WITH CHECK ADD  CONSTRAINT FK_11005_11000 FOREIGN KEY(cert_typ_cod_id) REFERENCES dbo.t_11000 (cert_typ_cod_id);

ALTER TABLE dbo.t_12005  WITH CHECK ADD  CONSTRAINT FK_12005_12000 FOREIGN KEY(add_cod_typ_id) REFERENCES dbo.t_12000 (add_cod_typ_id);
                                                              
ALTER TABLE dbo.t_14005  WITH CHECK ADD  CONSTRAINT FK_14005_14000 FOREIGN KEY(meas_typ_ser_id) REFERENCES dbo.t_14000 (meas_typ_ser_id);
                                                              
ALTER TABLE dbo.t_15005  WITH CHECK ADD  CONSTRAINT FK_15005_15000 FOREIGN KEY(regi_id) REFERENCES dbo.t_15000 (regi_id);
                                                              
ALTER TABLE dbo.t_16005  WITH CHECK ADD  CONSTRAINT FK_16005_16000 FOREIGN KEY(rol_typ_id) REFERENCES dbo.t_16000 (rol_typ_id);
                                                              
ALTER TABLE dbo.t_20000  WITH CHECK ADD  CONSTRAINT FK_20000_10000 FOREIGN KEY(footn_typ_id) REFERENCES dbo.t_10000 (footn_typ_id);
                                                              
ALTER TABLE dbo.t_20005  WITH CHECK ADD  CONSTRAINT FK_20005_20000 FOREIGN KEY(footn_typ_id, footn_id) REFERENCES dbo.t_20000 (footn_typ_id, footn_id);
                                                              
ALTER TABLE dbo.t_20010  WITH CHECK ADD  CONSTRAINT FK_20010_20000 FOREIGN KEY(footn_typ_id, footn_id) REFERENCES dbo.t_20000 (footn_typ_id, footn_id);
ALTER TABLE dbo.t_20010  WITH CHECK ADD  CONSTRAINT FK_20010_20005 FOREIGN KEY(descr_per_footn_sid) REFERENCES dbo.t_20005 (descr_per_footn_sid);
                                                              
ALTER TABLE dbo.t_20500  WITH CHECK ADD  CONSTRAINT FK_20500_11000 FOREIGN KEY(cert_typ_cod_id) REFERENCES dbo.t_11000 (cert_typ_cod_id);
                                                              
ALTER TABLE dbo.t_20505  WITH CHECK ADD  CONSTRAINT FK_20505_20500 FOREIGN KEY(cert_typ_cod_id, cert_ref_no) REFERENCES dbo.t_20500 (cert_typ_cod_id, cert_ref_no);
                                                              
ALTER TABLE dbo.t_20510  WITH CHECK ADD  CONSTRAINT FK_20510_20500 FOREIGN KEY(cert_typ_cod_id, cert_ref_no) REFERENCES dbo.t_20500 (cert_typ_cod_id, cert_ref_no);
ALTER TABLE dbo.t_20510  WITH CHECK ADD  CONSTRAINT FK_20510_20505 FOREIGN KEY(cert_descr_sid) REFERENCES dbo.t_20505 (cert_descr_sid);
                                                              
ALTER TABLE dbo.t_21005  WITH CHECK ADD  CONSTRAINT FK_21005_21000 FOREIGN KEY(meas_unit_cod_id) REFERENCES dbo.t_21000 (meas_unit_cod_id);

ALTER TABLE dbo.t_21505  WITH CHECK ADD  CONSTRAINT FK_21505_21500 FOREIGN KEY(meas_unit_qual_cod_id) REFERENCES dbo.t_21500 (meas_unit_qual_cod_id);

ALTER TABLE dbo.t_22505  WITH CHECK ADD  CONSTRAINT FK_22505_22500 FOREIGN KEY(mon_unit_cod_id) REFERENCES dbo.t_22500 (mon_unit_cod_id)

ALTER TABLE dbo.t_23005  WITH CHECK ADD  CONSTRAINT FK_23005_23000 FOREIGN KEY(duty_expr_id) REFERENCES dbo.t_23000 (duty_expr_id)

ALTER TABLE dbo.t_23500  WITH CHECK ADD  CONSTRAINT FK_23500_14000 FOREIGN KEY(meas_typ_ser_id) REFERENCES dbo.t_14000 (meas_typ_ser_id)

ALTER TABLE dbo.t_23505  WITH CHECK ADD  CONSTRAINT FK_23505_23500 FOREIGN KEY(meas_typ_id) REFERENCES dbo.t_23500 (meas_typ_id)

ALTER TABLE dbo.t_24500  WITH CHECK ADD  CONSTRAINT FK_24500_12000 FOREIGN KEY(add_cod_typ_id) REFERENCES dbo.t_12000 (add_cod_typ_id)

ALTER TABLE dbo.t_24505  WITH CHECK ADD  CONSTRAINT FK_24505_24500 FOREIGN KEY(add_cod_sid) REFERENCES dbo.t_24500 (add_cod_sid)

ALTER TABLE dbo.t_24510  WITH CHECK ADD  CONSTRAINT FK_24510_24500 FOREIGN KEY(add_cod_sid) REFERENCES dbo.t_24500 (add_cod_sid)
ALTER TABLE dbo.t_24510  WITH CHECK ADD  CONSTRAINT FK_24510_24505 FOREIGN KEY(add_cod_descr_sid) REFERENCES dbo.t_24505 (add_cod_descr_sid)

ALTER TABLE dbo.t_24515  WITH CHECK ADD  CONSTRAINT FK_24515_20000 FOREIGN KEY(footn_typ_id, footn_id) REFERENCES dbo.t_20000 (footn_typ_id, footn_id)
ALTER TABLE dbo.t_24515  WITH CHECK ADD  CONSTRAINT FK_24515_24500 FOREIGN KEY(add_cod_sid) REFERENCES dbo.t_24500 (add_cod_sid)

ALTER TABLE dbo.t_25000  WITH CHECK ADD  CONSTRAINT FK_25000_25000 FOREIGN KEY(par_geo_area_sid) REFERENCES dbo.t_25000 (geo_area_sid)

ALTER TABLE dbo.t_25005  WITH CHECK ADD  CONSTRAINT FK_25005_25000 FOREIGN KEY(geo_area_sid) REFERENCES dbo.t_25000 (geo_area_sid)

ALTER TABLE dbo.t_25010  WITH CHECK ADD  CONSTRAINT FK_25010_25000 FOREIGN KEY(geo_area_sid) REFERENCES dbo.t_25000 (geo_area_sid)
ALTER TABLE dbo.t_25010  WITH CHECK ADD  CONSTRAINT FK_25010_25005 FOREIGN KEY(geo_area_descr_sid) REFERENCES dbo.t_25005 (geo_area_descr_sid)

ALTER TABLE dbo.t_25015  WITH CHECK ADD  CONSTRAINT FK1_25015_25000 FOREIGN KEY(geo_area_sid) REFERENCES dbo.t_25000 (geo_area_sid)
ALTER TABLE dbo.t_25015  WITH CHECK ADD  CONSTRAINT FK2_25015_25000 FOREIGN KEY(geo_area_group_sid) REFERENCES dbo.t_25000 (geo_area_sid)

ALTER TABLE dbo.t_27005  WITH CHECK ADD  CONSTRAINT FK_27005_27000 FOREIGN KEY(nom_gro_typ, goods_nom_gro_id) REFERENCES dbo.t_27000 (nom_gro_typ, goods_nom_gro_id)

ALTER TABLE dbo.t_27500  WITH CHECK ADD  CONSTRAINT FK_27500_16000 FOREIGN KEY(com_abr_rol_typ_id) REFERENCES dbo.t_16000 (rol_typ_id)

ALTER TABLE dbo.t_28000  WITH CHECK ADD  CONSTRAINT FK_28000_16000 FOREIGN KEY(abr_rol_typ_id) REFERENCES dbo.t_16000 (rol_typ_id)

ALTER TABLE dbo.t_28500  WITH CHECK ADD  CONSTRAINT FK_28500_15000 FOREIGN KEY(regi_id) REFERENCES dbo.t_15000 (regi_id)
ALTER TABLE dbo.t_28500  WITH CHECK ADD  CONSTRAINT FK_28500_16000 FOREIGN KEY(bas_rol_typ_id) REFERENCES dbo.t_16000 (rol_typ_id)
ALTER TABLE dbo.t_28500  WITH CHECK ADD  CONSTRAINT FK_28500_27500 FOREIGN KEY(com_abr_rol_typ_id, com_abr_reg_id) REFERENCES dbo.t_27500 (com_abr_rol_typ_id, com_abr_reg_id)
ALTER TABLE dbo.t_28500  WITH CHECK ADD  CONSTRAINT FK_28500_28000 FOREIGN KEY(abr_rol_typ_id, abr_reg_id) REFERENCES dbo.t_28000 (abr_rol_typ_id, abr_reg_id)

ALTER TABLE dbo.t_29000  WITH CHECK ADD  CONSTRAINT FK_29000_16000 FOREIGN KEY(mod_bas_rol_typ_id) REFERENCES dbo.t_16000 (rol_typ_id)
ALTER TABLE dbo.t_29000  WITH CHECK ADD  CONSTRAINT FK_29000_27500 FOREIGN KEY(com_abr_rol_typ_id, com_abr_reg_id) REFERENCES dbo.t_27500 (com_abr_rol_typ_id, com_abr_reg_id)
ALTER TABLE dbo.t_29000  WITH CHECK ADD  CONSTRAINT FK_29000_28000 FOREIGN KEY(abr_rol_typ_id, abr_reg_id) REFERENCES dbo.t_28000 (abr_rol_typ_id, abr_reg_id)

ALTER TABLE dbo.t_29500  WITH CHECK ADD  CONSTRAINT FK_29500_16000 FOREIGN KEY(pror_rol_typ_id) REFERENCES dbo.t_16000 (rol_typ_id)

ALTER TABLE dbo.t_29505  WITH CHECK ADD  CONSTRAINT FK_29505_29500 FOREIGN KEY(pror_rol_typ_id, pror_rol_reg_id) REFERENCES dbo.t_29500 (pror_rol_typ_id, pror_rol_reg_id)

ALTER TABLE dbo.t_30000  WITH CHECK ADD  CONSTRAINT FK_30000_16000 FOREIGN KEY(fts_rol_typ_id) REFERENCES dbo.t_16000 (rol_typ_id)
ALTER TABLE dbo.t_30000  WITH CHECK ADD  CONSTRAINT FK_30000_27500 FOREIGN KEY(com_abr_rol_typ_id, com_abr_reg_id) REFERENCES dbo.t_27500 (com_abr_rol_typ_id, com_abr_reg_id)
ALTER TABLE dbo.t_30000  WITH CHECK ADD  CONSTRAINT FK_30000_28000 FOREIGN KEY(abr_rol_typ_id, abr_reg_id) REFERENCES dbo.t_28000 (abr_rol_typ_id, abr_reg_id)

ALTER TABLE dbo.t_30005  WITH CHECK ADD  CONSTRAINT FK_30005_30000 FOREIGN KEY(fts_rol_typ_id, fts_int_rol_reg_id) REFERENCES dbo.t_30000 (fts_rol_typ_id, fts_int_rol_reg_id)

ALTER TABLE dbo.t_35005  WITH CHECK ADD  CONSTRAINT FK_35005_35000 FOREIGN KEY(meas_cond_cod_id) REFERENCES dbo.t_35000 (meas_cond_cod_id)

ALTER TABLE dbo.t_35505  WITH CHECK ADD  CONSTRAINT FK_35505_35500 FOREIGN KEY(meas_act_cod_id) REFERENCES dbo.t_35500 (meas_act_cod_id)

ALTER TABLE dbo.t_36010  WITH CHECK ADD  CONSTRAINT FK_36010_25000 FOREIGN KEY(geo_area_sid) REFERENCES dbo.t_25000 (geo_area_sid)
ALTER TABLE dbo.t_36010  WITH CHECK ADD  CONSTRAINT FK_36010_36000 FOREIGN KEY(quota_order_sid) REFERENCES dbo.t_36000 (quota_order_sid)

ALTER TABLE dbo.t_36015  WITH CHECK ADD  CONSTRAINT FK_36015_25000 FOREIGN KEY(excl_geo_area_sid) REFERENCES dbo.t_25000 (geo_area_sid)
ALTER TABLE dbo.t_36015  WITH CHECK ADD  CONSTRAINT FK_36015_36010 FOREIGN KEY(quota_order_origin_sid) REFERENCES dbo.t_36010 (quota_order_origin_sid)

ALTER TABLE dbo.t_37000  WITH CHECK ADD  CONSTRAINT FK_37000_21000 FOREIGN KEY(meas_unit_cod_id) REFERENCES dbo.t_21000 (meas_unit_cod_id)
ALTER TABLE dbo.t_37000  WITH CHECK ADD  CONSTRAINT FK_37000_21500 FOREIGN KEY(meas_unit_qual_cod_id) REFERENCES dbo.t_21500 (meas_unit_qual_cod_id)
ALTER TABLE dbo.t_37000  WITH CHECK ADD  CONSTRAINT FK_37000_22500 FOREIGN KEY(mon_unit_cod_id) REFERENCES dbo.t_22500 (mon_unit_cod_id)
ALTER TABLE dbo.t_37000  WITH CHECK ADD  CONSTRAINT FK_37000_36000 FOREIGN KEY(quota_order_sid) REFERENCES dbo.t_36000 (quota_order_sid)

ALTER TABLE dbo.t_37005  WITH CHECK ADD  CONSTRAINT FK1_37005_37000 FOREIGN KEY(quota_def_main_sid) REFERENCES dbo.t_37000 (quota_def_sid)
ALTER TABLE dbo.t_37005  WITH CHECK ADD  CONSTRAINT FK2_37005_37000 FOREIGN KEY(quota_def_sub_sid) REFERENCES dbo.t_37000 (quota_def_sid)

ALTER TABLE dbo.t_37010  WITH CHECK ADD  CONSTRAINT FK1_37010_37000 FOREIGN KEY(quota_def_sid) REFERENCES dbo.t_37000 (quota_def_sid)

ALTER TABLE dbo.t_37015  WITH CHECK ADD  CONSTRAINT FK1_37015_37000 FOREIGN KEY(quota_def_sid) REFERENCES dbo.t_37000 (quota_def_sid)

ALTER TABLE dbo.t_37020  WITH CHECK ADD  CONSTRAINT FK1_37020_37000 FOREIGN KEY(quota_def_sid) REFERENCES dbo.t_37000 (quota_def_sid)

ALTER TABLE dbo.t_40005  WITH CHECK ADD  CONSTRAINT FK_40005_40000 FOREIGN KEY(nom_item_sid) REFERENCES dbo.t_40000 (nom_item_sid)

ALTER TABLE dbo.t_40010  WITH CHECK ADD  CONSTRAINT FK_40010_40000 FOREIGN KEY(nom_item_sid) REFERENCES dbo.t_40000 (nom_item_sid)

ALTER TABLE dbo.t_40015  WITH CHECK ADD  CONSTRAINT FK_40015_40000 FOREIGN KEY(nom_item_sid) REFERENCES dbo.t_40000 (nom_item_sid)
ALTER TABLE dbo.t_40015  WITH CHECK ADD  CONSTRAINT FK_40015_40010 FOREIGN KEY(descr_per_goods_nom_sid) REFERENCES dbo.t_40010 (descr_per_goods_nom_sid)

ALTER TABLE dbo.t_40020  WITH CHECK ADD  CONSTRAINT FK_40020_20000 FOREIGN KEY(footn_typ_id, footn_id) REFERENCES dbo.t_20000 (footn_typ_id, footn_id)
ALTER TABLE dbo.t_40020  WITH CHECK ADD  CONSTRAINT FK_40020_40000 FOREIGN KEY(nom_item_sid) REFERENCES dbo.t_40000 (nom_item_sid)

ALTER TABLE dbo.t_40025  WITH CHECK ADD  CONSTRAINT FK_40025_27000 FOREIGN KEY(nom_gro_typ, goods_nom_gro_id) REFERENCES dbo.t_27000 (nom_gro_typ, goods_nom_gro_id)
ALTER TABLE dbo.t_40025  WITH CHECK ADD  CONSTRAINT FK_40025_40000 FOREIGN KEY(nom_item_sid) REFERENCES dbo.t_40000 (nom_item_sid)

ALTER TABLE dbo.t_41000  WITH CHECK ADD  CONSTRAINT FK_41000_12000 FOREIGN KEY(add_cod_typ_id) REFERENCES dbo.t_12000 (add_cod_typ_id)
ALTER TABLE dbo.t_41000  WITH CHECK ADD  CONSTRAINT FK_41000_40000 FOREIGN KEY(nom_item_sid) REFERENCES dbo.t_40000 (nom_item_sid)

ALTER TABLE dbo.t_41005  WITH CHECK ADD  CONSTRAINT FK_41005_41000 FOREIGN KEY(exp_ref_nom_item_sid) REFERENCES dbo.t_41000 (exp_ref_nom_item_sid)

ALTER TABLE dbo.t_41010  WITH CHECK ADD  CONSTRAINT FK_41010_41000 FOREIGN KEY(exp_ref_nom_item_sid) REFERENCES dbo.t_41000 (exp_ref_nom_item_sid)

ALTER TABLE dbo.t_41015  WITH CHECK ADD  CONSTRAINT FK_41015_41000 FOREIGN KEY(exp_ref_nom_item_sid) REFERENCES dbo.t_41000 (exp_ref_nom_item_sid)
ALTER TABLE dbo.t_41015  WITH CHECK ADD  CONSTRAINT FK_41015_41010 FOREIGN KEY(exp_ref_nom_item_sid_desc) REFERENCES dbo.t_41010 (exp_ref_nom_item_sid_desc)

ALTER TABLE dbo.t_41020  WITH CHECK ADD  CONSTRAINT FK_41020_20000 FOREIGN KEY(footn_typ_id, footn_id) REFERENCES dbo.t_20000 (footn_typ_id, footn_id)
ALTER TABLE dbo.t_41020  WITH CHECK ADD  CONSTRAINT FK_41020_41000 FOREIGN KEY(exp_ref_nom_item_sid) REFERENCES dbo.t_41000 (exp_ref_nom_item_sid)

ALTER TABLE dbo.t_43000  WITH CHECK ADD  CONSTRAINT FK_43000_23500 FOREIGN KEY(meas_typ_id) REFERENCES dbo.t_23500 (meas_typ_id)
ALTER TABLE dbo.t_43000  WITH CHECK ADD  CONSTRAINT FK_43000_25000 FOREIGN KEY(geo_area_sid) REFERENCES dbo.t_25000 (geo_area_sid)
ALTER TABLE dbo.t_43000  WITH CHECK ADD  CONSTRAINT FK_43000_40000 FOREIGN KEY(nom_item_sid) REFERENCES dbo.t_40000 (nom_item_sid)
ALTER TABLE dbo.t_43000  WITH CHECK ADD  CONSTRAINT FK_43000_41000 FOREIGN KEY(exp_ref_nom_item_sid) REFERENCES dbo.t_41000 (exp_ref_nom_item_sid)

ALTER TABLE dbo.t_43005  WITH CHECK ADD  CONSTRAINT FK_43005_21000 FOREIGN KEY(meas_unit) REFERENCES dbo.t_21000 (meas_unit_cod_id)
ALTER TABLE dbo.t_43005  WITH CHECK ADD  CONSTRAINT FK_43005_22500 FOREIGN KEY(mon_unit_cod) REFERENCES dbo.t_22500 (mon_unit_cod_id)
ALTER TABLE dbo.t_43005  WITH CHECK ADD  CONSTRAINT FK_43005_23000 FOREIGN KEY(duty_expr_id) REFERENCES dbo.t_23000 (duty_expr_id)
ALTER TABLE dbo.t_43005  WITH CHECK ADD  CONSTRAINT FK_43005_43000 FOREIGN KEY(meas_sid) REFERENCES dbo.t_43000 (meas_sid)

ALTER TABLE dbo.t_43010  WITH CHECK ADD  CONSTRAINT FK_43010_20500 FOREIGN KEY(cert_typ_cod_id, cert_ref_no) REFERENCES dbo.t_20500 (cert_typ_cod_id, cert_ref_no)
ALTER TABLE dbo.t_43010  WITH CHECK ADD  CONSTRAINT FK_43010_21000 FOREIGN KEY(cond_meas_unit) REFERENCES dbo.t_21000 (meas_unit_cod_id)
ALTER TABLE dbo.t_43010  WITH CHECK ADD  CONSTRAINT FK_43010_22500 FOREIGN KEY(cond_mon_unit) REFERENCES dbo.t_22500 (mon_unit_cod_id)
ALTER TABLE dbo.t_43010  WITH CHECK ADD  CONSTRAINT FK_43010_35000 FOREIGN KEY(cond_typ_cod) REFERENCES dbo.t_35000 (meas_cond_cod_id)
ALTER TABLE dbo.t_43010  WITH CHECK ADD  CONSTRAINT FK_43010_35500 FOREIGN KEY(act_cod) REFERENCES dbo.t_35500 (meas_act_cod_id)
ALTER TABLE dbo.t_43010  WITH CHECK ADD  CONSTRAINT FK_43010_43000 FOREIGN KEY(meas_sid) REFERENCES dbo.t_43000 (meas_sid)

ALTER TABLE dbo.t_43011  WITH CHECK ADD  CONSTRAINT FK_43011_21000 FOREIGN KEY(act_meas_unit) REFERENCES dbo.t_21000 (meas_unit_cod_id)
ALTER TABLE dbo.t_43011  WITH CHECK ADD  CONSTRAINT FK_43011_22500 FOREIGN KEY(act_mon_unit) REFERENCES dbo.t_22500 (mon_unit_cod_id)
ALTER TABLE dbo.t_43011  WITH CHECK ADD  CONSTRAINT FK_43011_23000 FOREIGN KEY(duty_expr_id) REFERENCES dbo.t_23000 (duty_expr_id)
ALTER TABLE dbo.t_43011  WITH CHECK ADD  CONSTRAINT FK_43011_43010 FOREIGN KEY(meas_cond_sid) REFERENCES dbo.t_43010 (meas_cond_sid)

ALTER TABLE dbo.t_43015  WITH CHECK ADD  CONSTRAINT FK_43015_25000 FOREIGN KEY(geo_area_sid) REFERENCES dbo.t_25000 (geo_area_sid)
ALTER TABLE dbo.t_43015  WITH CHECK ADD  CONSTRAINT FK_43015_43000 FOREIGN KEY(meas_sid) REFERENCES dbo.t_43000 (meas_sid)

ALTER TABLE dbo.t_43020  WITH CHECK ADD  CONSTRAINT FK_43020_20000 FOREIGN KEY(footn_typ_id, footn_id) REFERENCES dbo.t_20000 (footn_typ_id, footn_id)
ALTER TABLE dbo.t_43020  WITH CHECK ADD  CONSTRAINT FK_43020_43000 FOREIGN KEY(meas_sid) REFERENCES dbo.t_43000 (meas_sid)

ALTER TABLE dbo.t_43025  WITH CHECK ADD  CONSTRAINT FK_43025_43000 FOREIGN KEY(meas_sid) REFERENCES dbo.t_43000 (meas_sid)

GO

-- national part of TARIC
-------------------------

-- note.to.goods
create table dbo.c_chapt_note 
		(note_sid int identity(-1, -1) not null, -- note.sid
		nom_item_sid int  null, -- goods.nomenclature.sid
		section_sid int  null, -- goods.section.sid
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		note_fi nvarchar(max)  null, -- finnish.note
		note_en nvarchar(max)  null, -- english.note
		note_sv nvarchar(max)  null, -- swedish.note
		 constraint PK_chapt_note primary key clustered (note_sid asc));

-- duty.type.for.measure
create table dbo.c_meas_duty 
		(meas_duty_sid int identity(-1, -1) not null, -- measurement.duty.sid
		meas_typ_ser_id char(2)  null, -- measure.type.series.id
		meas_typ_id char(6)  null, -- measure.type
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		duty_cod char(3) not null, -- duty.type
		comment nvarchar(500)  null, -- comment
		 constraint PK_meas_duty primary key clustered (meas_duty_sid asc));

-- preference.for.measure
create table dbo.c_meas_pref 
		(meas_pref_sid int identity(-1, -1) not null, -- measure.prefrerence.sid
		pref_cod char(3) not null, -- preference.code
		meas_typ_id char(6) not null, -- measure.type
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		regi_id char(3)  null, -- regulation.group.id
		comment nvarchar(500)  null, -- comment
		 constraint PK_meas_pref primary key clustered (meas_pref_sid asc));

-- preference
create table dbo.c_preference 
		(pref_cod char(3) not null, -- preference.code
		dat_start date not null, -- validity.start.date
		dat_end date  null, -- validity.end.date
		descr_fi nvarchar(500)  null, -- finnish.description
		descr_en nvarchar(500)  null, -- english.description
		descr_sv nvarchar(500)  null, -- swedish.description
		 constraint PK_preference primary key clustered (pref_cod asc));

GO

ALTER TABLE dbo.c_chapt_note WITH CHECK
	ADD CONSTRAINT FK_chapt_note_40000 FOREIGN KEY(nom_item_sid)
	REFERENCES dbo.t_40000 (nom_item_sid)
	ON DELETE CASCADE;

ALTER TABLE dbo.c_meas_duty WITH CHECK
	ADD CONSTRAINT FK_meas_duty_14000 FOREIGN KEY(meas_typ_ser_id)
	REFERENCES dbo.t_14000 (meas_typ_ser_id)
	ON DELETE CASCADE;

ALTER TABLE dbo.c_meas_duty WITH CHECK 
	ADD CONSTRAINT FK_meas_duty_23500 FOREIGN KEY(meas_typ_id)
	REFERENCES dbo.t_23500 (meas_typ_id)
	ON DELETE CASCADE;

ALTER TABLE dbo.c_meas_pref WITH CHECK 
	ADD CONSTRAINT FK_meas_pref_preference FOREIGN KEY(pref_cod)
	REFERENCES dbo.c_preference (pref_cod)
	ON DELETE CASCADE;

ALTER TABLE dbo.c_meas_pref WITH CHECK 
	ADD CONSTRAINT FK_meas_pref_23500 FOREIGN KEY(meas_typ_id)
	REFERENCES dbo.t_23500 (meas_typ_id)
	ON DELETE CASCADE;

ALTER TABLE dbo.c_meas_pref WITH CHECK 
	ADD CONSTRAINT FK_meas_pref_15000 FOREIGN KEY(regi_id)
	REFERENCES dbo.t_15000 (regi_id)
	ON DELETE CASCADE;

GO

--------------------------------------