2.1. Database Usage and SQL DML Statements
16 Questions
1 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

What is the purpose of the SQL SELECT statement?

  • To update existing records in a table
  • To delete records from a table
  • To retrieve data from one or more tables (correct)
  • To insert new records into a table

What does the WHERE clause do in an SQL statement?

  • It groups rows that have the same values
  • It specifies the order of the results
  • It filters records based on a specified condition (correct)
  • It retrieves all columns from a table

In the SQL INSERT statement, what does the VALUES clause specify?

  • The order in which the data will be displayed
  • The table from which the data is retrieved
  • The actual data to be inserted into the specified columns (correct)
  • The specific columns to be updated

Which SQL command will modify existing records in a table?

<p>UPDATE (D)</p> Signup and view all the answers

What will happen if the WHERE clause is omitted in an UPDATE statement?

<p>All records in the table will be updated (B)</p> Signup and view all the answers

Which of the following is a valid example of a SQL SELECT statement?

<p>SELECT VARDAS, ATLYGINIMAS FROM DARBUOTOJAI (B)</p> Signup and view all the answers

In an SQL DELETE statement, what does the WHERE clause determine?

<p>Which records are to be deleted (D)</p> Signup and view all the answers

What does the GROUP BY clause do in an SQL query?

<p>It combines rows that have the same values in specified columns (C)</p> Signup and view all the answers

What will happen if the DELETE statement does not include a WHERE clause?

<p>All records in the table will be deleted. (A)</p> Signup and view all the answers

Which of the following SQL statements correctly selects employees with salaries between 500 and 700?

<p>SELECT NAME FROM EMPLOYEES WHERE SALARY BETWEEN 500 AND 700; (C)</p> Signup and view all the answers

What does the SQL WHERE clause allow you to do?

<p>Filter records based on specified conditions. (B)</p> Signup and view all the answers

Which symbol can be used in a SQL statement to match any single character?

<p>_ (B)</p> Signup and view all the answers

What will the statement 'SELECT CODE FROM EMPLOYEES WHERE NAME IN ('John', 'Doe')' return?

<p>Employee codes for John and Doe only. (D)</p> Signup and view all the answers

How would you update an employee's surname in the EMPLOYEES table where the first name is 'John'?

<p>UPDATE EMPLOYEES SET SURNAME = 'Smith' WHERE FIRST_NAME = 'John'; (C)</p> Signup and view all the answers

What does the SQL statement 'DROP TABLE employees' do?

<p>Removes the employees table and all its records permanently. (A)</p> Signup and view all the answers

Which SQL command would you use to find all employees who do not have a store ID assigned?

<p>SELECT * FROM EMPLOYEES WHERE STORE_ID IS NULL; (B)</p> Signup and view all the answers

Flashcards

SQL UPDATE

Used to modify existing data in a table. Specify the table, column to update, new value, and matching condition (WHERE).

SQL DELETE

Removes rows from a table based on a specified condition. If no condition is given, it deletes all rows.

SQL DROP TABLE

Permanently removes a table and all of its data from the database.

SQL WHERE clause (equality)

Filters records in a table based on a given condition. e.g., WHERE column = 'value'.

Signup and view all the flashcards

SQL WHERE clause (BETWEEN)

Selects records within a range of values using BETWEEN ... AND ... . Includes both start and end values.

Signup and view all the flashcards

SQL WHERE clause (IN)

Selects records where a column's value matches any value in a list.

Signup and view all the flashcards

SQL WHERE clause (LIKE)

Selects rows where a column value matches a pattern (wildcard characters).

Signup and view all the flashcards

SQL NULL

Represents missing or unknown data in a database column.

Signup and view all the flashcards

SQL WHERE clause (IS NULL)

Selects rows where a column has a NULL value.

Signup and view all the flashcards

SQL wildcard (%)

Matches any sequence of zero or more characters.

Signup and view all the flashcards

SQL wildcard (_)

Matches any single character.

Signup and view all the flashcards

SQL SELECT Statement

Used to retrieve data from one or more tables. The result is a table called a 'Result-Set'.

Signup and view all the flashcards

SQL SELECT *

Selects all columns from a table.

Signup and view all the flashcards

SQL SELECT with columns

Selects specific columns from a table.

Signup and view all the flashcards

SQL WHERE Clause

Filters data based on a condition.

Signup and view all the flashcards

SQL INSERT Statement

Adds new rows to a table.

Signup and view all the flashcards

SQL UPDATE Statement

Modifies existing rows in a table.

Signup and view all the flashcards

SQL DELETE Statement

Removes rows from a table.

Signup and view all the flashcards

SQL FROM Clause

Specifies the table(s) to retrieve data from.

Signup and view all the flashcards

SQL Single Quotes

Used to enclose text values, dates, and times

Signup and view all the flashcards

SQL Double Quotes

Used when necessary for column names that have special characters

Signup and view all the flashcards

SQL GROUP BY Clause

Groups rows with the same values in specified columns.

Signup and view all the flashcards

SQL ORDER BY Clause

Sorts rows based on specified column(s).

Signup and view all the flashcards

SQL HAVING Clause

Filters grouped rows based on a condition.

Signup and view all the flashcards

Study Notes

Database Usage, SQL

  • SQL is used for manipulating and retrieving data from databases.
  • DML (Data Manipulation Language) statements are used to manage data within a database.

DML Statements

  • SELECT: Retrieves data from one or more tables.
  • INSERT: Adds new rows into a table.
  • UPDATE: Modifies existing rows in a table.
  • DELETE: Removes existing rows from a table.
  • FROM: Specifies the table(s) from which to retrieve data.
  • WHERE: Filters data based on a specified condition.
  • GROUP BY: Groups rows with the same values in a column(s).
  • ORDER BY: Sorts the results based on one or more columns.
  • HAVING: Filters grouped data based on a condition.

SQL SELECT Statement

  • Used to retrieve data from a table or tables.
  • The result is a result-set, which is a table form.
  • Syntax:
    • SELECT column1, column2, ... FROM table_name;
    • SELECT * FROM table_name; (* means all columns*)

SQL WHERE Clause

  • Filters data based on a condition.
  • Syntax:
    • SELECT column1, column2, ... FROM table_name WHERE condition;

SQL INSERT Statement

  • Used to add new rows to a table.
  • Syntax:
    • INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);

SQL UPDATE Statement

  • Used to modify existing rows in a table.
  • Syntax:
    • UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;

SQL DELETE Statement

  • Used to remove rows from a table.
  • Syntax:
    • DELETE FROM table_name WHERE condition;

SQL WHERE Clause (Operators)

  • BETWEEN: Matches values within a specified range.
  • IN: Matches values in a list.
  • LIKE: Matches patterns. % matches any sequence of characters, _ matches any single character.
  • NOT: Negates a condition.
  • AND: Combines conditions that must both be true
  • OR: Combines conditions where at least one must be true
  • IS NULL: Checks for null values.

SQL GROUP BY

  • Groups rows that have similar values in specified columns.
  • Used with aggregate functions.
  • Aggregate Functions:
    • AVG(): Calculates the average.
    • COUNT(): Counts the number of rows.
    • MAX(): Finds the maximum value.
    • MIN(): Finds the minimum value.
    • SUM(): Calculates the sum

SQL HAVING Clause

  • Filters grouped data based on a condition.
  • Used after a GROUP BY clause.

SQL Additional functions

  • DISTINCT: Retrieves only unique values.
  • LOWER: Converts strings to lowercase.
  • UPPER: Converts strings to uppercase.
  • CONCAT: Concatenates strings.

SQL Syntax summary

  • General syntax: SELECT columns FROM table WHERE condition GROUP BY grouping_columns HAVING condition ORDER BY ordering_columns

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

This quiz covers the manipulation and retrieval of data using SQL, focusing on Data Manipulation Language (DML) statements. Participants will learn about key commands such as SELECT, INSERT, UPDATE, and DELETE, along with filtering and sorting options to manage database queries effectively.

More Like This

Operaciones DML en SQL
15 questions

Operaciones DML en SQL

IrresistibleRed avatar
IrresistibleRed
Operaciones DML de SQL
10 questions

Operaciones DML de SQL

IrresistibleRed avatar
IrresistibleRed
Oracle SQL Data Manipulation (DML) Review
10 questions
Use Quizgecko on...
Browser
Browser