Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SQL Primary and Foreign Key Tables already created and data in them. Unable to use the alter SQL because of null values: Alter table returns

SQL Primary and Foreign Key

Tables already created and data in them. Unable to use the alter SQL because of null values:

Alter table returns

add primary key (return_id)

I was able to add primary key using:

ALTER TABLE RETURNS

ADD CONSTRAINT PK_Returns PRIMARY KEY (ORDER_ID,RETURNED);

However, I cannot get foreign key to work. I get the following error:

Error starting at line : 1 in command -

ALTER TABLE Returns

ADD FOREIGN KEY (order_id) REFERENCES Orders(order_id)

Error report -

SQL Error: ORA-02270: no matching unique or primary key for this column-list

02270. 00000 - "no matching unique or primary key for this column-list"

*Cause: A REFERENCES clause in a CREATE/ALTER TABLE statement

gives a column-list for which there is no matching unique or primary

key constraint in the referenced table.

*Action: Find the correct column names using the ALL_CONS_COLUMNS

catalog view

Need help constructing the SQL commands for the keys.

1. Create a primary key for the RETURNS table and create a foreign key on RETURNS table that references the ORDERS tables. All tables have data already in them.

Address (address_id, postal_code, state, region, country)

Category (category_id, category, sub_category)

Orderline (order_id), product_id)

Orders (row_id, order_id, order_date, ship_date, ship_mode, customer_id, address_id, product_id, product_name, quantity)

Product (product_id, product_name, category_id, sales, discount, customer_id)

Superstore (row_id, order_id, order_date, ship_date, ship_mode, customer_id, customer_name, segment, country, city, state, postal_code, region, product_id, category, sub_category, product_name, sales, quantity, discount, profit)

Returned (returned, order, reason)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions