Podcast Beta
Questions and Answers
What are the two major components of SQL?
SQL has two major components: a Data Definition Language (DDL) for defining the database structure and a Data Manipulation Language (DML) for retrieving and updating data.
What type of commands does SQL lack?
SQL lacks flow control commands such as IF...THEN … ELSE, GOTO, WHILE … DO.
What are the four Data Manipulation Language (DML) statements in SQL?
The four DML statements in SQL are: SELECT, INSERT, UPDATE, and DELETE.
What columns does the Stock Item Relation table have?
Signup and view all the answers
What columns does the Sales Relation table have?
Signup and view all the answers
What columns does the Branches Relation table have?
Signup and view all the answers
What is the purpose of the WHERE clause in a SQL statement?
Signup and view all the answers
What is the purpose of the AND, OR, and NOT logical operators in conditional statements?
Signup and view all the answers
What is the order of evaluation for conditional expressions in SQL?
Signup and view all the answers
What is the purpose of the BETWEEN operator in a SQL statement?
Signup and view all the answers
What is the purpose of the SELECT statement in a SQL query?
Signup and view all the answers
What is the purpose of the FROM clause in a SQL statement?
Signup and view all the answers
How do you specify multiple conditions in a WHERE clause?
Signup and view all the answers
What is the purpose of the OR operator in a WHERE clause?
Signup and view all the answers
What does the LIKE operator %e
match in a string?
Signup and view all the answers
What does the condition Address LIKE '%Nicosia%'
match?
Signup and view all the answers
What does the condition Address NOT LIKE 'H%'
mean?
Signup and view all the answers
What is the purpose of the IS NULL
condition?
Signup and view all the answers
What is the minimum stock level for the monitor with code MON 15?
Signup and view all the answers
What is the effect of adding ASC
to an ORDER BY
clause?
Signup and view all the answers
How many CDWR were sold on 1/12/03?
Signup and view all the answers
How can you sort a query by multiple columns?
Signup and view all the answers
Which branch is located in Nicosia?
Signup and view all the answers
What is the price of a 20 GB Disk (DIS 20)?
Signup and view all the answers
What is the purpose of the LIKE
operator with a wildcard?
Signup and view all the answers
What is the purpose of the IS NOT NULL
condition?
Signup and view all the answers
How many KEY 04 were sold on 3/12/03?
Signup and view all the answers
What is the primary purpose of the SELECT statement in SQL?
Signup and view all the answers
What is the current stock level of the Main Board (MB 100)?
Signup and view all the answers
In the SELECT statement, what clause is used to filter rows based on certain conditions?
Signup and view all the answers
Which item has the lowest sale price?
Signup and view all the answers
How many CD 52 were sold on 2/12/03?
Signup and view all the answers
What are the two mandatory clauses in the SELECT statement?
Signup and view all the answers
What is the purpose of the GROUP BY clause in the SELECT statement?
Signup and view all the answers
What is the difference between the WHERE and HAVING clauses in the SELECT statement?
Signup and view all the answers
How can you retrieve all columns in a table using the SELECT statement?
Signup and view all the answers
Study Notes
Search Conditions
- In conditional statements, the following logical operators are used:
- = (Equals)
- < (Less than)
- > (Greater than)
- ≤ (Less than or equal)
- ≥ (Greater than or equal)
- ≠(Not equal to)
- More complex predicates can be generated using AND, OR, and NOT.
- The rule of evaluation for conditional expressions is:
- Expressions are evaluated left to right
- Expressions inserted in brackets are evaluated first
- NOTs are evaluated before ANDs and ORs
- ANDs are evaluated before ORs
Compound Comparisons
- Example: List all sales of 64 MB VGA or Keyboard by Sales-Date, Branch-Number, Stock-Code
- The result shows the sales of 64 MB VGA or Keyboard by Sales-Date, Branch-Number, Stock-Code
Range Search Condition (BETWEEN / NOT BETWEEN)
- Example: List all stocks whose Stock-Quantity is between 5 and 50 by Stock-Code, Stock-Quantity
- The SQL statement uses the BETWEEN operator to filter the results
Structured Query Language (SQL)
- SQL is a transform-oriented and non-procedure language designed to use relations to transform inputs into required outputs
- SQL has two major components:
- A Data Definition Language (DDL) for defining the database structure
- A Data Manipulation Language (DML) for retrieving and updating data
- SQL contains only definitional and manipulative commands, and does not contain flow control commands
- SQL can be used in two ways:
- Use SQL interactively by entering the statements at the terminal
- Embed SQL statements in a procedural language
SQL DML Statements
- Data manipulation statements in SQL are:
- SELECT: To query data in the database
- INSERT: To insert data into a table
- UPDATE: To update data in a table
- DELETE: To delete data from a table
SELECT Statement
- The purpose of the SELECT statement is to retrieve and display data from one or more database tables
- The general format of the SELECT statement is:
SELECT [DISTENCT/ALL] {*/[Column – Expression]}
FROM Table name(s)
[WHERE condition]
[GROUP BY Column – list][HAVING Condition]
[ORDER BY Column – list]
- The SELECT statement is extremely powerful and can perform the equivalent of relational algebra's selection, projection, and join in a single statement
- The order of the clauses in the SELECT statement cannot be changed
Null Search Condition (IS NULL/IS NOT NULL)
- Example: List the entries in the Sales where there is no date entry
- The result shows the entries in the Sales where there is no date entry
Sorting the Results (ORDER BY)
- The sorting may be in ASC (ascending) or DESC (descending) order
- The sorting may be used on single column or multiple columns
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.