Home » Developer & Programmer » Data Integration » Load Data into fact table
Load Data into fact table [message #652745] |
Fri, 17 June 2016 11:04 |
|
charlie2016
Messages: 4 Registered: June 2016
|
Junior Member |
|
|
Hi,
Am trying to load data into the sales fact table however i get the error below after running the query
insert into sales
(market_Id,product_Id,time_Id,sales_Amt)
values (1,1002,(SELECT time_Id from time where year = 1997),2500);
SQL Error: ORA-02291: integrity constraint (HR.SYS_C0014611) violated - parent key not found
02291. 00000 - "integrity constraint (%s.%s) violated - parent key not found"
*Cause: A foreign key value has no matching primary key value.
*Action: Delete the foreign key or add a matching primary key.
Below are the tables and the sql queries:
CREATE TABLE MARKET (
market_Id NUMBER PRIMARY KEY,
city VARCHAR2(15),
state VARCHAR2(3),
region CHAR(1)
);
insert into market values (1,'Melb','Vic','A');
insert into market values (2,'Adelaide','SA','A');
insert into market values (3,'Brisbane','Qld','A');
insert into market values (4,'Perth','WA','A');
CREATE TABLE PRODUCT (
product_Id NUMBER PRIMARY KEY,
name VARCHAR2(20),
category VARCHAR2(15),
price NUMBER(5,2)
);
insert into product values (1001,'Pens','Stationary',5.00);
insert into product values (1002,'Pencil','Stationary',2.00);
insert into product values (1003,'Book','Stationary',6.00);
insert into product values (1004,'Ink','Stationary',3.50);
select * from product;
CREATE TABLE TIME (
time_Id DATE PRIMARY KEY,
week NUMBER(2),
month CHAR(3),
quarter NUMBER(1),
year NUMBER(4)
);
insert into time values (sysdate,1,'MAR',3,1993);
insert into time values (sysdate,2,'SEP',4,1995);
insert into time values (sysdate,3,'SEP',4,1995);
insert into time values ('15-OCT-2000',1,'NOV',2,1997);
insert into time values ('16-DEC-2012',3,'OCT',3,1996);
select * from time;
update time set TIME_ID='6-JUL-2012' where year=1995 and week=2;
CREATE TABLE SALES (
market_Id NUMBER REFERENCES MARKET,
product_Id NUMBER REFERENCES PRODUCT,
time_Id DATE REFERENCES TIME,
sales_Amt NUMBER(7,2),
PRIMARY KEY (market_Id,product_Id,time_Id)
);
insert into sales
(market_Id,product_Id,time_Id,sales_Amt)
values (1,1002,(SELECT time_Id from time where year = 1997),2500);
Please advise.
|
|
|
Goto Forum:
Current Time: Thu Apr 18 13:59:47 CDT 2024
|