Run sql command line, issue. Creating tables - sql

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)
);

Related

FOREIGN KEY references invalid

CREATE TABLE MEDICO (
DNIMedico CHAR(9) NOT NULL,
NumeroColegiado VARCHAR(200) NOT NULL,
Nombre VARCHAR(200) NOT NULL,
FechaNacimiento DATE NOT NULL,
CONSTRAINT pk_MEDICO PRIMARY KEY (DNIMedico)
)
CREATE TABLE PACIENTE (
DNIPaciente CHAR(9) NOT NULL,
Nombre VARCHAR(200) NOT NULL,
Direccion VARCHAR (200) NOT NULL,
Edad INT NOT NULL,
Peso FLOAT NOT NULL,
Altura FLOAT NOT NULL,
CONSTRAINT pk_PACIENTE PRIMARY KEY (DNIPaciente)
)
CREATE TABLE MEDICO_PACIENTE (
CONSTRAINT fkMP_MEDICO FOREIGN KEY (DNIMedico) REFERENCES
MEDICO (DNIMedico),
CONSTRAINT fkMP_PACIENTE FOREIGN KEY (DNIPaciente) REFERENCES
PACIENTE (DNIPaciente),
Especialidad VARCHAR(200) NOT NULL
)
Msg 1769, Level 16, State 1, Line 18
Foreign key 'fkMP_MEDICO' references invalid column 'DNIMedico' in referencing table 'MEDICO_PACIENTE'.
Msg 1750, Level 16, State 0, Line 18
Could not create constraint or index. See previous errors.
Declaring a foreign key does not automagically create a column. You need to declare the column first, then the foreign key.
Hence:
CREATE TABLE MEDICO_PACIENTE (
DNIMedico CHAR(9) NOT NULL,
DNIPaciente CHAR(9) NOT NULL,
Especialidad VARCHAR(200) NOT NULL,
CONSTRAINT fkMP_MEDICO FOREIGN KEY (DNIMedico) REFERENCES MEDICO (DNIMedico),
CONSTRAINT fkMP_PACIENTE FOREIGN KEY (DNIPaciente) REFERENCES PACIENTE (DNIPaciente)
);
Note that each refering columns should have the same datatype and length as the column they reference.
It would also be a good idea to declare a primary key for the MEDICO_PACIENTE table. Possibly, you want a compound primary key on (DNIMedico, DNIPaciente ):
CREATE TABLE MEDICO_PACIENTE (
DNIMedico CHAR(9) NOT NULL,
DNIPaciente CHAR(9) NOT NULL,
Especialidad VARCHAR(200) NOT NULL,
CONSTRAINT fkMP_MEDICO FOREIGN KEY (DNIMedico) REFERENCES MEDICO (DNIMedico),
CONSTRAINT fkMP_PACIENTE FOREIGN KEY (DNIPaciente) REFERENCES PACIENTE (DNIPaciente),
CONSTRAINT pk_MEDICO_PACIENTE PRIMARY KEY (DNIMedico, DNIPaciente)
);
Demo on DB Fiddle

Why do my CREATE TABLES work alone but not together? [duplicate]

This question already has answers here:
How do I execute multiple SQL Statements in Access' Query Editor?
(6 answers)
Closed 4 years ago.
I am trying to run a script with multiple CREATE TABLE statements in MS Access.
When I try to run the script all together I get a CREATE TABLE syntax error on the 2nd CREATE TABLE, but when I run each CREATE TABLE on its own through a SQL validator they pass successfully.
What am I doing wrong by lumping all the CREATE TABLEs into one script?
CREATE TABLE MODEL (
ModelNum INT NOT NULL,
Capacity INT NOT NULL,
MaxRange INT NOT NULL,
CONSTRAINT ModelPK PRIMARY KEY(ModelNum)
);
CREATE TABLE AIRPLANE (
RegNum INT NOT NULL,
ModelNum INT NOT NULL,
CONSTRAINT AirplanePK PRIMARY KEY(RegNum),
CONSTRAINT AirplaneFK FOREIGN KEY(ModelNum) REFERENCES MODEL(ModelNum)
);
CREATE TABLE EMPLOYEE (
SSN INT NOT NULL,
EmpName VARCHAR(100) NOT NULL,
Phone INT NULL,
UnionMemberNum INT NULL,
CONSTRAINT EmployeePK PRIMARY KEY(SSN)
);
CREATE TABLE TECHNICIAN (
SSN INT NOT NULL,
Salary INT NOT NULL,
CONSTRAINT TechnicianPK PRIMARY KEY(SSN),
CONSTRAINT TechnicianFK FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN)
);
CREATE TABLE TRAFFICCONTROLLER (
SSN INT NOT NULL,
DateOfTraining DATE NULL,
CONSTRAINT TrafficControllerPK1 PRIMARY KEY(SSN),
CONSTRAINT TrafficControllerFK1 FOREIGN KEY(SSN) REFERENCES EMPLOYEE(SSN)
);
CREATE TABLE EXPERT(
SSN INT NOT NULL,
ModelNum INT NOT NULL,
CONSTRAINT ExpertPK1 PRIMARY KEY(SSN),
CONSTRAINT ExpertFK1 FOREIGN KEY(ModelNum) REFERENCES AIRPLANE(ModelNum)
);
CREATE TABLE TEST(
Test_Num INT NOT NULL,
TestName VARCHAR(100) NOT NULL,
MaxScore INT NOT NULL,
CONSTRAINT TestPK PRIMARY KEY(Test_Num)
);
CREATE TABLE TESTEVENTS(
RegNum INT NOT NULL,
Test_Num INT NOT NULL,
SSN INT NOT NULL,
TestDate DATE NOT NULL,
Score INT NULL,
CONSTRAINT TestEventsPK1 PRIMARY KEY(RegNum),
CONSTRAINT TestEventsFK1 FOREIGN KEY(RegNum) REFERENCES AIRPLANE(RegNum),
CONSTRAINT TestEventsPK2 PRIMARY KEY(Test_Num),
CONSTRAINT TestEventsFK2 FOREIGN KEY(Test_Num) REFERENCES TEST(Test_Num),
CONSTRAINT TestEventsPK3 PRIMARY KEY(SSN),
CONSTRAINT TestEventsFK3 FOREIGN KEY(SSN) REFERENCES TECHNICIAN(SSN),
CONSTRAINT TestEventsPK4 PRIMARY KEY(TestDate)
);
MS Access supports only one statement at a time.

"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.

SQL DB Creation Error

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);

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.