Create Table SALE( SaleID integer, SaleDate date, Tax decimal, Total decimal);Create Table ITEM( ItemID integer, Name char(30), Cost decimal, Price decimal);Create Table SALE_ITEM( SaleID integer, SaleItemID integer);Considering the SQL create statements; assume that SALE, SALE_ITEM and ITEM tables were created without Primary Keys and Foreign Keys. Which of the following SQL statements gives an error?Question 12Select one:a.Alter Table SALE Add Primary Key (SaleID);Alter Table SALE_ITEM Add Primary Key (SaleID);Alter Table SALE Add Foreign Key (SaleID) References SALE_ITEM;b.Alter Table SALE Add Primary Key (SaleID);Alter Table SALE_ITEM Add Primary Key (SaleID, SaleItemID);Alter Table SALE_ITEM Add Unique (SaleID);Alter Table SALE Add Foreign Key (SaleID) References SALE_ITEM (SaleID);c.Alter Table SALE Add Primary Key (SaleID);Alter Table SALE_ITEM Add Primary Key (SaleID, SaleItemID);Alter Table SALE_ITEM Add Unique (SaleID);Alter Table ITEM Add Primary Key (ItemID);Alter Table SALE Add Foreign Key (SaleID) References SALE_ITEM;d.Alter Table ITEM Add Primary Key (ItemID);Alter Table SALE_ITEM Add Primary Key (SaleID, SaleItemID);Alter Table SALE_ITEM Add Unique (SaleID);Alter Table ITEM Add Foreign Key (ItemID) References SALE_ITEM;
Question
Create Table SALE( SaleID integer, SaleDate date, Tax decimal, Total decimal);Create Table ITEM( ItemID integer, Name char(30), Cost decimal, Price decimal);Create Table SALE_ITEM( SaleID integer, SaleItemID integer);Considering the SQL create statements; assume that SALE, SALE_ITEM and ITEM tables were created without Primary Keys and Foreign Keys. Which of the following SQL statements gives an error?Question 12Select one:a.Alter Table SALE Add Primary Key (SaleID);Alter Table SALE_ITEM Add Primary Key (SaleID);Alter Table SALE Add Foreign Key (SaleID) References SALE_ITEM;b.Alter Table SALE Add Primary Key (SaleID);Alter Table SALE_ITEM Add Primary Key (SaleID, SaleItemID);Alter Table SALE_ITEM Add Unique (SaleID);Alter Table SALE Add Foreign Key (SaleID) References SALE_ITEM (SaleID);c.Alter Table SALE Add Primary Key (SaleID);Alter Table SALE_ITEM Add Primary Key (SaleID, SaleItemID);Alter Table SALE_ITEM Add Unique (SaleID);Alter Table ITEM Add Primary Key (ItemID);Alter Table SALE Add Foreign Key (SaleID) References SALE_ITEM;d.Alter Table ITEM Add Primary Key (ItemID);Alter Table SALE_ITEM Add Primary Key (SaleID, SaleItemID);Alter Table SALE_ITEM Add Unique (SaleID);Alter Table ITEM Add Foreign Key (ItemID) References SALE_ITEM;
Solution
The SQL statement that gives an error is:
d. Alter Table ITEM Add Primary Key (ItemID); Alter Table SALE_ITEM Add Primary Key (SaleID, SaleItemID); Alter Table SALE_ITEM Add Unique (SaleID); Alter Table ITEM Add Foreign Key (ItemID) References SALE_ITEM;
Explanation: In this statement, there is an error in the last part where it tries to add a foreign key constraint between the ITEM table and the SALE_ITEM table. The error occurs because the foreign key reference is made to the ITEM table's primary key (ItemID), but the SALE_ITEM table does not have a corresponding column named ItemID.
Similar Questions
Given the following statements: S1: A foreign key declaration can always be replaced by an equivalent check assertion in SQL. S2: Given the table R(a,b,c) where a and b together form the primary key, the following is a valid table definition. CREATE TABLE S ( ConstINTEGER, d INTEGER, e INTEGER, PRIMARY KEY (d), FOREIGN KEY (a) references R) Which one of the following statements is CORRECT?
Which of the following statements can be used to add a new primary key to an existing table that has no primary key? *1 pointADD PRIMARY KEY TO TABLE table_name(column_name)ALTER TABLE table_name ADD CONSTRAINT PRIMARY KEY(column_name)ALTER TABLE table_name ADD PRIMARY KEY(column_name)ADD PRIMARY KEY (column_name) TO table_name
Which of the following do you need to consider when you make a table in SQL?a.Data typesb.Primary keysc.Default valuesd.All of the mentioned
Which of the following is the correct syntax to create a table with a foreign key constraint in SQL? *1 pointCREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT, FOREIGN KEY(customer_id) REFERENCES customers(customer_id))CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT REFERENCES customers(customer_id))CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT, CONSTRAINT fk_customer FOREIGN KEY(customer_id) REFERENCES customers(customer_id))CREATE TABLE orders (order_id INT PRIMARY KEY, customer_id INT, CONSTRAINT fk_customer REFERENCES customers(customer_id))
Which of the statement(S) are incorrect w.r.t primary key in SQL. A. A primary key can contain duplicate values to ensure redundancy.B. A primary key can be a composite key, consisting of multiple columns.C. A primary key must be an auto-increment field.D. A primary key cannot be null
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.