Query error: there is no matching unique or primary key constraint in the referenced table I am getting an error of 

*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 


for my code

create table comm_Customer(CustomerID numeric primary key, 
                           CustomerName varchar(20),  
                           Address varchar(30),  
                           PhoneNumber numeric,  
                           foreign key(CustomerID)  
                               references comm_ShoppingCart(CustomerID));
The error message is clear, you are trying to incorporate a FOREIGN KEY on table comm_Customer that says that the CustomerID (which is it's primary key) is also related to table's comm_ShoppingCart CustomerID column. This would mean that every customer might have a shopping cart (but only 1), since CustomerID has to be a primary key (or unique) on the comm_ShoppingCart to correctly identify a unique row of that table with the foreign key relationship.

I believe the relationship is the other way arround, comm_ShoppingCart CustomerID should reference table's comm_Customer CustomerID which IS a primary key and won't display this error message.

If this is the case, you can add the FOREIGN KEY with an ALTER TABLE if it's already created:

ALTER TABLE comm_ShoppingCart 
    ADD CONSTRAINT FK_comm_ShoppingCart_comm_Customer 
    FOREIGN KEY (CustomerID) 
    REFERENCES comm_Customer (CustomerID)


If you really want the other way around, you have to create a UNIQUE constraint (or index) on CustomerID column on the comm_ShoppingCart table:

ALTER TABLE comm_ShoppingCart
    ADD CONSTRAINT UNI_comm_ShoppingCart_CustomerID
    UNIQUE (CustomerID)


... which will fail if you have more than 1 cart for a particular customer.