SQL DB Creation Error - sql

I used BIT DEFAULT 0, as a Boolean dont know if its right like that. Well, the problem is that I cannot create any table because there is a problem in FK, dont get why? I'ev also added ERD Image for better view.
Maybe someone will/can be so nice and explain it to me, ty!
Maybe someone know any good program or online sandbox for turtnind ERD to the MSSQL Code or MySQL code? It would be nice if its free for use. Thanks in advance!
CREATE DataBase LO;
GO
USE LO;
CREATE TABLE Weapon
(
ClassWeapon CHAR(50) NULL,
Level INT NULL,
MinDmg INT NULL,
MaxDmg INT NULL,
AtkSpeed NUMERIC(3,2) NULL,
PerSecondDmg NUMERIC(6,2) NULL,
PlayerLevel INT NULL,
SkillLevel INT NULL,
Image BIT DEFAULT 0 NULL,
Name CHAR(100) NULL,
Weapons CHAR(50) NOT NULL,
Monsters CHAR(50) NULL,
PRIMARY KEY (Weapons),
FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Armor
(
ClassArmor CHAR(50) NULL,
Name CHAR(100) NULL,
Level INT NULL,
Defense INT NULL,
Image BIT DEFAULT 0 NULL,
Armors CHAR(50) NOT NULL,
Monsters CHAR(50) NULL,
PRIMARY KEY (Armors),
FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Menu
(
Weapons CHAR(50) NULL,
Armors CHAR(50) NULL,
Monsters CHAR(50) NULL,
FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons),
FOREIGN KEY (Armors) REFERENCES Armor(Armors),
FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Monster
(
Name CHAR(100) NULL,
Level INT NULL,
MinHealth INT NULL,
MaxHealth INT NULL,
MinDmg INT NULL,
MaxDmg INT NULL,
AtkSpeed NUMERIC(3,2) NULL,
Location CHAR(100) NULL,
Monsters CHAR(50) NOT NULL,
DropItems CHAR(100) NULL,
Image BIT DEFAULT 0 NULL,
PRIMARY KEY (Monsters),
FOREIGN KEY (DropItems) REFERENCES Items(DropItems)
);
CREATE TABLE Items
(
DropItems CHAR(100) NOT NULL,
Weapons CHAR(50) NULL,
Armors CHAR(50) NULL,
PRIMARY KEY (DropItems),
FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons),
FOREIGN KEY (Armors) REFERENCES Armor(Armors)
);

Well, the problem is that I cannot create any table because there is a problem in FK, dont get why?
Simply, you cannot reference object that does not exist.
You should first create tables and then add FK relationships:
CREATE DataBase LO;
GO
USE LO;
CREATE TABLE Weapon
(
ClassWeapon CHAR(50) NULL,
Level INT NULL,
MinDmg INT NULL,
MaxDmg INT NULL,
AtkSpeed NUMERIC(3,2) NULL,
PerSecondDmg NUMERIC(6,2) NULL,
PlayerLevel INT NULL,
SkillLevel INT NULL,
Image BIT DEFAULT 0 NULL,
Name CHAR(100) NULL,
Weapons CHAR(50) NOT NULL,
Monsters CHAR(50) NULL,
PRIMARY KEY (Weapons),
--FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Armor
(
ClassArmor CHAR(50) NULL,
Name CHAR(100) NULL,
Level INT NULL,
Defense INT NULL,
Image BIT DEFAULT 0 NULL,
Armors CHAR(50) NOT NULL,
Monsters CHAR(50) NULL,
PRIMARY KEY (Armors),
---- FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Menu
(
Weapons CHAR(50) NULL,
Armors CHAR(50) NULL,
Monsters CHAR(50) NULL,
--FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons),
-- FOREIGN KEY (Armors) REFERENCES Armor(Armors),
-- FOREIGN KEY (Monsters) REFERENCES Monster(Monsters)
);
CREATE TABLE Monster
(
Name CHAR(100) NULL,
Level INT NULL,
MinHealth INT NULL,
MaxHealth INT NULL,
MinDmg INT NULL,
MaxDmg INT NULL,
AtkSpeed NUMERIC(3,2) NULL,
Location CHAR(100) NULL,
Monsters CHAR(50) NOT NULL,
DropItems CHAR(100) NULL,
Image BIT DEFAULT 0 NULL,
PRIMARY KEY (Monsters),
--FOREIGN KEY (DropItems) REFERENCES Items(DropItems)
);
CREATE TABLE Items
(
DropItems CHAR(100) NOT NULL,
Weapons CHAR(50) NULL,
Armors CHAR(50) NULL,
PRIMARY KEY (DropItems),
--FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons),
-- FOREIGN KEY (Armors) REFERENCES Armor(Armors)
);
ALTER TABLE Weapon
ADD FOREIGN KEY (Monsters) REFERENCES Monster(Monsters);
ALTER TABLE Armor
ADD FOREIGN KEY (Monsters) REFERENCES Monster(Monsters);
ALTER TABLE Menu
ADD
FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons),
FOREIGN KEY (Armors) REFERENCES Armor(Armors),
FOREIGN KEY (Monsters) REFERENCES Monster(Monsters);
ALTER TABLE Monster
ADD FOREIGN KEY (DropItems) REFERENCES Items(DropItems);
ALTER TABLE Items
ADD FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons),
FOREIGN KEY (Armors) REFERENCES Armor(Armors);

Thanks #lad2025
Here how it worked by adding Tables and then alter the FK.
CREATE DataBase LO;
GO
USE LO;
CREATE TABLE Weapon
(
ClassWeapon CHAR(50) NULL,
Level INT NULL,
MinDmg INT NULL,
MaxDmg INT NULL,
AtkSpeed NUMERIC(3,2) NULL,
PerSecondDmg NUMERIC(6,2) NULL,
PlayerLevel INT NULL,
SkillLevel INT NULL,
Image BIT DEFAULT 0 NULL,
Name CHAR(100) NULL,
Weapons CHAR(50) NOT NULL,
Monsters CHAR(50) NULL,
PRIMARY KEY (Weapons)
);
ALTER TABLE Weapon ADD FOREIGN KEY (Monsters) REFERENCES Monster(Monsters);
CREATE TABLE Armor
(
ClassArmor CHAR(50) NULL,
Name CHAR(100) NULL,
Level INT NULL,
Defense INT NULL,
Image BIT DEFAULT 0 NULL,
Armors CHAR(50) NOT NULL,
Monsters CHAR(50) NULL,
PRIMARY KEY (Armors)
);
ALTER TABLE Armor ADD FOREIGN KEY (Monsters) REFERENCES Monster(Monsters);
CREATE TABLE Menu
(
Weapons CHAR(50) NULL,
Armors CHAR(50) NULL,
Monsters CHAR(50) NULL
);
ALTER TABLE Menu ADD FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons);
ALTER TABLE Menu ADD FOREIGN KEY (Armors) REFERENCES Armor(Armors);
ALTER TABLE Menu ADD FOREIGN KEY (Monsters) REFERENCES Monster(Monsters);
CREATE TABLE Monster
(
Name CHAR(100) NULL,
Level INT NULL,
MinHealth INT NULL,
MaxHealth INT NULL,
MinDmg INT NULL,
MaxDmg INT NULL,
AtkSpeed NUMERIC(3,2) NULL,
Location CHAR(100) NULL,
Monsters CHAR(50) NOT NULL,
DropItems CHAR(100) NULL,
Image BIT DEFAULT 0 NULL,
PRIMARY KEY (Monsters)
);
ALTER TABLE Monster ADD FOREIGN KEY (DropItems) REFERENCES Items(DropItems);
CREATE TABLE Items
(
DropItems CHAR(100) NOT NULL,
Weapons CHAR(50) NULL,
Armors CHAR(50) NULL,
PRIMARY KEY (DropItems)
);
ALTER TABLE Items ADD FOREIGN KEY (Weapons) REFERENCES Weapon(Weapons);
ALTER TABLE Items ADD FOREIGN KEY (Armors) REFERENCES Armor(Armors);

Related

How to reference to primary key?

create database [PostaShpejte]
use PostaShpejte
create table Posta
(
ID_Posta int not null Primary Key,
Emri varchar(50)not null,
Qyteti varchar(15) not null,
)
create table Dergesa
(
ID_Dergesa int IDENTITY(1,1) not null Primary Key,
Emri_Dergeses varchar(30) not null,
Pershkrimi varchar(100),
Qmimi int not null,
Statusi varchar(30) not null,
CONSTRAINT CHK_Statusi CHECK (Statusi='E regjistruar' or Statusi='E nisur' or Statusi='Ne depo' or Statusi='E refuzuar' or Statusi='E derguar'),
)
create table Menaxhon
(
ID_Dergesa int not null references Dergesa (ID_Dergesa),
ID_Posta int not null references Posta(ID_Posta),
Primary Key(ID_Dergesa,ID_Posta),
)
--drop table TelBleresi
create table TelBleresi
(
ID_Tel_Bleresi int not null,
--ID_Bleresi int not null,
NumriTel int not null Unique,
Primary Key(ID_Tel_Bleresi),
)
--drop table Bleresi
create table Bleresi
(
ID_Bleresi int not null,
ID_Tel_Bleresi int not null,
Emri varchar(20) not null,
Mbiemri varchar(20) not null,
Shteti varchar(20) not null,
Qyteti varchar(20) not null,
Rruga varchar(50) not null,
ZIPKodi int not null,
FOREIGN KEY(ID_Tel_Bleresi) references TelBleresi(ID_Tel_Bleresi),
Primary Key (ID_Bleresi , ID_Tel_Bleresi),
)
create table Dergohet
(
ID_Dergesa int not null,
ID_Bleresi int not null,
Data_e_regj date not null,
Data_e_mbrritjes date not null,
----------------PROBLEM HERE---------------------------
FOREIGN KEY (ID_Dergesa) references Dergesa(ID_Dergesa),
FOREIGN KEY (ID_Bleresi) references **Bleresi**(ID_Bleresi),
*Error: There are no primary or candidate key to table Bleresi ....*
---------------------------------------------------------
PRIMARY KEY (ID_Dergesa,ID_Bleresi),
)
Bleresi has a compound primary key (ID_Bleresi, ID_Tel_Bleresi), so you need to reference all columns. That means adding ID_Tel_Bleresi to Dergohet.
create table Dergohet(
ID_Dergesa int not null,
ID_Bleresi int not null,
ID_Tel_Bleresi int not null, -- add this column
Data_e_regj date not null,
Data_e_mbrritjes date not null,
FOREIGN KEY (ID_Dergesa) references Dergesa(ID_Dergesa),
-- Reference the full compound key
FOREIGN KEY (ID_Bleresi, ID_Tel_Bleresi) references Bleresi(ID_Bleresi, ID_Tel_Bleresi),
PRIMARY KEY (ID_Dergesa,ID_Bleresi),
)
While they have some uses, compound primary keys are annoying as they create a proliferation of foreign key columns and complicate indexing. Some of yours seem unnecessary: Bleresi already has a ID_Bleresi, is that not unique?
In general, I'd recommend using simple big integer (2 billion creeps up on you surprisingly fast) auto incrementing primary keys. If you need to guarantee other uniquenesses, make a unique index.
The error say that ID_Bleresi is not the primary key on Bleresi table and for that can't be a foreign key. The primary key is:
Primary Key (ID_Bleresi , ID_Tel_Bleresi)
If ID_Bleresi is not a unique column, I recommend that in the table, you create a new unique column that is the primary key. In case it is, it would be best to set ID_Bleresi as the unique primary key

How to select a common attribute from 2 different tables, with the highest appearence of a mutual attribute?

So i have a table "accident", and the attribute "pess_segura" which is the number of an ensured person envolved in an accidente.
I also have a table "acid_pess" which has 2 relevant attributes for this problem "accident" and "pessoa", this table refers to people envolved in accidents that are not ensured (they were involved in an accident but they were not driving).
So i want to select the accident with most people envolved.
These are the relevant tables for this exercise
create table person(
n_pess bigint not null,
nif integer not null,
cart_cond varchar(15),
pais_cart_cond varchar(30),
doc_id varchar(15) not null,
pais_doc_id varchar(30) not null,
nome varchar(80) not null,
primary key(n_pess),
unique(nif),
unique(cart_cond),
unique(doc_id)
);
create table ensurance(
apolice bigint not null,
ensured bigint not null,
veiculo bigint not null,
datai date not null,
dataf date not null,
cobertura numeric(10,2) not null,
primary key(apolice),
unique(ensured, veiculo),
foreign key (ensured) references person(n_pess),
foreign key (veiculo) references veiculo(n_veic)
);
create table accident(
n_acid bigint not null,
pess_segura bigint not null,
veic_seguro bigint not null,
data date not null,
local varchar(255) not null,
descr text not null,
primary key(n_acid),
unique(n_acid, veic_seguro),
foreign key (pess_segura,veic_seguro) references ensurance(ensured, veiculo)
);
create table acid_pess(
accident bigint not null,
person bigint not null,
veiculo bigint not null,
descr text not null,
primary key(accident, person),
foreign key (accident) references accident(n_acid),
foreign key (person) references person(n_pess),
foreign key (accident, veiculo) references accident(n_acid, veic_seguro)
);
I want to select the n_acid(number of the accident) that had the most people envolved.

"ORA-00907: missing right parenthesis" in foreign key declaration

I am a university student who are new to Oracle Live SQL. My professor give us one page of code and let us debugging.
Only 1 error in the last paragraph(Enrollment TABLE) left. All tables except Enrollment table have been successfully created. I spent 6 hours on last paragraph but still can not find the wrong place. I have checked all the information on the web and did not find solution.
Please help, thanks!
CREATE TABLE Faculty (
FacNo CHAR(11) NOT NULL,
FacFirstName VARCHAR(30) NOT NULL,
FacLastName VARCHAR(30) NOT NULL,
FacCity VARCHAR(30) NOT NULL,
FacState CHAR(2) NOT NULL,
FacDept CHAR(6) NULL,
FacRank CHAR(4) NULL,
FacSalary DECIMAL(10,2) NULL,
FacSupervisor CHAR(11) NULL,
FacHireDate DATE NULL,
FacZipCode CHAR(10) NOT NULL,
CONSTRAINT FacultyPK PRIMARY KEY (FacNo),
CONSTRAINT SupervisorFK FOREIGN KEY (FacSupervisor) REFERENCES Faculty);
CREATE TABLE Course (
CourseNo CHAR(6) NOT NULL,
CrsDesc VARCHAR(50) NOT NULL,
CrsUnits INTEGER NULL,
CONSTRAINT CoursePK PRIMARY KEY (CourseNo) );
CREATE TABLE Offering (
OfferNo INTEGER NOT NULL,
CourseNo CHAR(6) NOT NULL,
OffTerm CHAR(6) NOT NULL,
OffYear INTEGER NOT NULL,
OffLocation VARCHAR(30) NULL,
OffTime VARCHAR(10) NULL,
FacNo CHAR(11) NULL,
OffDays CHAR(4) NULL,
CONSTRAINT OfferingPK PRIMARY KEY (OfferNo),
CONSTRAINT CourseFK FOREIGN KEY (CourseNo) REFERENCES Course,
CONSTRAINT FacultyFK FOREIGN KEY (FacNo) REFERENCES Faculty);
CREATE TABLE Student (
StdNo CHAR(11) NOT NULL,
StdFirstName VARCHAR(30) NOT NULL,
StdLastName VARCHAR(30) NOT NULL,
StdCity VARCHAR(30) NOT NULL,
StdState CHAR(2) NOT NULL,
StdZip CHAR(10) NOT NULL,
StdMajor CHAR(6) NULL,
StdClass CHAR(2) NULL,
StdGPA DECIMAL(3,2) NULL,
CONSTRAINT StudentPk PRIMARY KEY (StdNo) )
CREATE TABLE Enrollment(
OfferNo INTEGER NOT NULL,
StdNo CHAR(11) NOT NULL,
EnrGrade DECIMAL(3,2) NULL,
CONSTRAINT EnrollmentPK PRIMARY KEY (OfferNo,StdNo),
CONSTRAINT OfferingFK FOREIGN KEY (OfferNo) REFERENCES Offering
ON DELETE CASCADE
ON UPDATE CASCADE,
CONSTRAINT StudentFK FOREIGN KEY (StdNo) REFERENCES Student
ON DELETE CASCADE
ON UPDATE CASCADE);
First of all, there is missing semicolon at the end of the CREATE TABLE Student statement.
But I believe that what your teacher wants to emphasize is that ON UPDATE is not supported by Oracle foreign keys. As far as concerns, Oracle's point of view is that primary keys are meant to be immutable.
If you comment this part of the statement, the code runs fine :
CREATE TABLE Enrollment(
OfferNo INTEGER NOT NULL,
StdNo CHAR(11) NOT NULL,
EnrGrade DECIMAL(3,2) NULL,
CONSTRAINT EnrollmentPK PRIMARY KEY (OfferNo,StdNo),
CONSTRAINT OfferingFK FOREIGN KEY (OfferNo) REFERENCES Offering
ON DELETE CASCADE,
-- ON UPDATE CASCADE,
CONSTRAINT StudentFK FOREIGN KEY (StdNo) REFERENCES Student
ON DELETE CASCADE
-- ON UPDATE CASCADE
);
Demo on DB Fiddle.

Run sql command line, issue. Creating tables

I'm trying to create a table in run sql command line of oracle database 11 xe.
My problem is when I finish typing my code:
create table vigilantes(
idVigilantes integer(3) not null,
nombre varchar(100) not null,
paterno varchar(100) not null,
materno varchar(100) not null,
id_caseta integer(3) null,
id_turno integer(3) null,
edad integer(3) not null,
id_genero integer(1) not null,
idEmpresa integer(3) not null,
constraint pk_idVigilantes PRIMARY KEY (idVigilantes)
constraint fk_id_caseta FOREIGN KEY (id_caseta)
references Caseta(id_caseta)
constraint fk_id_turno FOREIGN KEY(id_turno)
references Turno(id_turno)
constraint fk_id_genero FOREIGN KEY(id_genero)
references Generos(id_genero)
constraint fk_idEmpresa FOREIGN KEY(idEmpresa)
references Empresa(idEmpresa)
);
I get "ORA-00907: missing right parenthesis" issue.
I read that this is often caused by not defining a value.
e.g:
create table vigilantes(
idVigilantes integer not null,
.......
But still no solution here.
Any help or clue will be a lot of help.
You are missing comma after constraints. Also, integer has no precision.
create table vigilantes (
idVigilantes integer not null,
nombre varchar(100) not null,
paterno varchar(100) not null,
materno varchar(100) not null,
id_caseta integer null,
id_turno integer null,
edad integer not null,
id_genero integer not null,
idEmpresa integer not null,
constraint pk_idVigilantes primary key (idVigilantes),
constraint fk_id_caseta foreign key (id_caseta) references Caseta(id_caseta),
constraint fk_id_turno foreign key (id_turno) references Turno(id_turno),
constraint fk_id_genero foreign key (id_genero) references Generos(id_genero),
constraint fk_idEmpresa foreign key (idEmpresa) references Empresa(idEmpresa)
);
If you must define precision, use number datatype:
create table vigilantes (
idVigilantes number(3, 0) not null,
nombre varchar(100) not null,
paterno varchar(100) not null,
materno varchar(100) not null,
id_caseta number(3, 0) null,
id_turno number(3, 0) null,
edad number(3, 0) not null,
id_genero number(1, 0) not null,
idEmpresa number(3, 0) not null,
constraint pk_idVigilantes primary key (idVigilantes),
constraint fk_id_caseta foreign key (id_caseta) references Caseta(id_caseta),
constraint fk_id_turno foreign key (id_turno) references Turno(id_turno),
constraint fk_id_genero foreign key (id_genero) references Generos(id_genero),
constraint fk_idEmpresa foreign key (idEmpresa) references Empresa(idEmpresa)
);

Foreign key constraint error during SQL Server table creation

I am trying to create a table on SQL Server which has foreign key constraints.I checked all my parent tables and their primary keys match with my new foreign key constraints. Can someone help me out in resolving this issue. My DDL and error message are as below.
DDL
CREATE TABLE I_IPV_LOB_PROG_PROV_MO_METRIC_TRNS(
AARP_ORG_ID int NOT NULL,
LOB_ID int NOT NULL,
PGM_CAT_ID int NOT NULL,
PGM_ID int NOT NULL,
PROV_ID int NOT NULL,
CAT_OF_MEAS_ID int NOT NULL,
SUBCAT_OF_MEAS_ID int NOT NULL,
MEAS_ID int NOT NULL,
TYPE_OF_METRIC_ID int NOT NULL,
METRIC_VAL_ROLE_ID int NOT NULL,
MO_ID int NOT NULL,
OPER_TXT varchar(5) NULL,
METRIC_VAL decimal(19, 2) NOT NULL,
LST_UPD_DT datetime NOT NULL,
LOAD_DT datetime NULL,
LST_UPD_USERID char(20) NOT NULL,
CONSTRAINT PK79 PRIMARY KEY NONCLUSTERED (TYPE_OF_METRIC_ID, METRIC_VAL_ROLE_ID, AARP_ORG_ID, LOB_ID, PGM_CAT_ID, PGM_ID, PROV_ID, MEAS_ID, MO_ID, CAT_OF_MEAS_ID, SUBCAT_OF_MEAS_ID),
CONSTRAINT RefI_IPV_TYPE_OF_METRIC_TRNS73 FOREIGN KEY (TYPE_OF_METRIC_ID)
REFERENCES I_IPV_TYPE_OF_METRIC_TRNS(TYPE_OF_METRIC_ID),
CONSTRAINT RefI_IPV_METRIC_VAL_ROLE_TRNS75 FOREIGN KEY (METRIC_VAL_ROLE_ID)
REFERENCES I_IPV_METRIC_VAL_ROLE_TRNS(METRIC_VAL_ROLE_ID),
CONSTRAINT RefI_IPV_LOB_PROG_PROV_MEAS_TRNS345 FOREIGN KEY (AARP_ORG_ID,LOB_ID,PGM_CAT_ID,PGM_ID,PROV_ID,MEAS_ID,CAT_OF_MEAS_ID,SUBCAT_OF_MEAS_ID)
REFERENCES I_IPV_LOB_PROG_PROV_MEAS_TRNS(AARP_ORG_ID,LOB_ID,PGM_CAT_ID,PGM_ID,PROV_ID,MEAS_ID,CAT_OF_MEAS_ID,SUB_CAT_OF_MEAS_ID)
)
go
Parent Table DDL
CREATE TABLE I_IPV_LOB_PROG_PROV_MEAS_TRNS(
AARP_ORG_ID int NOT NULL,
LOB_ID int NOT NULL,
PGM_CAT_ID int NOT NULL,
PGM_ID int NOT NULL,
PROV_ID int NOT NULL,
CAT_OF_MEAS_ID int NOT NULL,
SUBCAT_OF_MEAS_ID int NOT NULL,
MEAS_ID int NOT NULL,
LOAD_DT datetime NULL,
LST_UPD_USERID char(20) NOT NULL,
LST_UPD_DT datetime NOT NULL,
CONSTRAINT PK115 PRIMARY KEY NONCLUSTERED (MEAS_ID, PROV_ID, AARP_ORG_ID, LOB_ID, PGM_ID, PGM_CAT_ID, CAT_OF_MEAS_ID, SUBCAT_OF_MEAS_ID),
CONSTRAINT RefI_IPV_LOB_PROG_CAT_PROV_TRNS322 FOREIGN KEY (PROV_ID, AARP_ORG_ID, LOB_ID, PGM_ID, PGM_CAT_ID)
REFERENCES I_IPV_LOB_PROG_CAT_PROV_TRNS(PROV_ID, AARP_ORG_ID, LOB_ID, PGM_ID, PGM_CAT_ID),
CONSTRAINT RefI_IPV_MEAS_CAT_TRNS342 FOREIGN KEY (MEAS_ID, CAT_OF_MEAS_ID, SUBCAT_OF_MEAS_ID)
REFERENCES I_IPV_MEAS_CAT_TRNS(MEAS_ID, CAT_OF_MEAS_ID, SUBCAT_OF_MEAS_ID)
)
go
Error Msg
Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'I_IPV_LOB_PROG_PROV_MEAS_TRNS' that match the referencing column list in the foreign key 'RefI_IPV_LOB_PROG_PROV_MEAS_TRNS345'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.
One of the fields in the target table must be its primary key (best) or be very quickly findable via some index using the at least one of nthe fields you've listed. If there are no keys in your list it will have to read the whole table to find the specific row and this is not a good thing to do, so it won't.
Create a unique index on the target table containing some/all of the fields you're constraining and it should be OK.