SQL Statements and Constraints Quiz
10 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Which SQL statement correctly updates the stock table when 100 items with code A1 are sold?

  • update stock set quantity=quantity - 100 having code=A1
  • update stock set quantity=quantity - 100 where code=A1 (correct)
  • update stock set quantity=100 where code=A1
  • delete from stock set quantity=quantity - 100 where code=A1

What is the correct SQL statement to delete the product with code A1 from the stock table?

  • delete from stock where code=A1 (correct)
  • delete from stock having code=A1
  • drop from stock where code=A1
  • update stock where code=A1

Which constraint should be used to ensure that an attribute always has a value?

  • Not null (correct)
  • Unique
  • Null
  • Distinct

What is the correct syntax to create a view with the name 'v'?

<p>Create view v as 'query expression' (C)</p> Signup and view all the answers

Which option is used to delete entries in the department table when a corresponding entry is deleted in the course table?

<p>On delete cascade (A)</p> Signup and view all the answers

Which SQL statement is needed to update the stock table so that 100 items with code A1 are deducted from the quantity?

<p>UPDATE stock SET quantity = quantity - 100 WHERE code = A1 (D)</p> Signup and view all the answers

In order to successfully delete a record with code A1 from the stock table, which SQL statement should be used?

<p>DELETE FROM stock WHERE code = A1 (B)</p> Signup and view all the answers

Which constraint ensures that an attribute in a database table cannot be left empty?

<p>Not null (C)</p> Signup and view all the answers

What is the correct syntax for creating a view named 'v' that executes a specific query?

<p>CREATE VIEW v AS query expression (C)</p> Signup and view all the answers

When deleting an entry in the course table, which option ensures that related entries in the department table are also removed?

<p>ON DELETE CASCADE (B)</p> Signup and view all the answers

Flashcards

SQL UPDATE stock (quantity)

Used to decrease the quantity of a stock item (code A1) by 100.

SQL DELETE from stock (code A1)

Removes a product from the stock table. Removes the entire row with code A1.

NOT NULL constraint

Ensures an attribute has a value; it can't be empty.

SQL CREATE VIEW syntax

Creates a view (virtual table) from a query, named "v".

Signup and view all the flashcards

ON DELETE CASCADE (in SQL)

If a row in one table is deleted, corresponding rows in another (related) table are also deleted.

Signup and view all the flashcards

SQL UPDATE stock for code A1

Decreases the quantity of a stock item with code 'A1' by 100.

Signup and view all the flashcards

SQL DELETE for code A1

Removes the product row with a code 'A1' from the stock table.

Signup and view all the flashcards

NOT NULL constraint

Forces attributes to have values; prevents empty entries.

Signup and view all the flashcards

SQL CREATE VIEW syntax

Creates a 'view' (virtual table) that displays the results of a query.

Signup and view all the flashcards

ON DELETE CASCADE

Deletes related rows in a different table automatically when a row is deleted from a referencing table.

Signup and view all the flashcards

More Like This

Use Quizgecko on...
Browser
Browser