Explore basic SQL principles with practical examples, covering core commands, logical and relational operators, table relationships, and data queries within relational databases. Perfect for newcomers seeking to understand SQL structure, queries, and syntax.
What does SQL stand for when referring to databases?
Explanation: SQL stands for Structured Query Language, which is a language used to interact with databases. 'Standard Query Listing' and 'System Query Line' are incorrect and do not represent SQL. 'Simple Question Logic' is also unrelated to databases or SQL.
Which SQL keyword is used to specify the table from which to retrieve data?
Explanation: The 'FROM' keyword tells SQL which table to retrieve data from. 'WHERE' is used to filter rows by condition, 'ORDER' is not a valid SQL keyword (the correct term is 'ORDER BY'), and 'GROUP' should be 'GROUP BY' for grouping data.
What is the main purpose of the SELECT statement in SQL?
Explanation: The 'SELECT' statement is used to get data from a database table or tables. It does not delete tables or change database names. Granting permissions is managed by special commands, not SELECT.
Which logical operator is used in SQL to require both conditions to be true?
Explanation: 'AND' makes sure that both conditions must be true for the result to be true. 'OR' only needs one condition to be true, 'NOT' reverses a condition’s result, and 'ALL' is unrelated to combining conditions.
In SQL, which keyword is used to filter records based on a specified condition?
Explanation: 'WHERE' filters records that meet a given condition. 'HAVING' is used with grouped data, 'UPDATE' changes data, and 'CREATE' is for new tables or databases.
How do you sort query results alphabetically by a field in SQL?
Explanation: The 'ORDER BY' clause arranges results, often in alphabetical order when used with text fields. 'GROUP BY' organizes rows into groups, 'ARRANGE BY' and 'SORT' are not valid SQL keywords.
Which symbol is used in SQL to represent 'not equal to'?
Explanation: '<>' means 'not equal to' in SQL syntax. '==' is not used in standard SQL for equality checking, '><' is not a recognized operator, and '--' is used for comments.
What is the main purpose of a primary key in a SQL table?
Explanation: A primary key provides a unique identifier for each row in a table, ensuring no duplicate entries. Backups are handled separately, references to other tables use foreign keys, and passwords should be stored in special fields, not as primary keys.
In SQL databases, what does a foreign key represent?
Explanation: A foreign key connects data between tables by referring to a primary key in another table. It's not a unique identifier in the same table (that is the primary key), nor does it relate to passwords or reserved commands.
Which SQL statement is used to create a new table in a database?
Explanation: 'CREATE TABLE' is the correct SQL command to make a new table. 'INSERT TABLE', 'ADD TABLE', and 'MAKE TABLE' are not valid SQL commands.
When writing a date value in SQL for Microsoft Access, which characters usually surround the date?
Explanation: In Microsoft Access SQL, date values are wrapped in hash marks (#). Single quotes are often used for text values, while dollar and ampersand symbols are not used for delimiting dates.
How would you retrieve only the 'game name' and 'release date' fields from a table named 'game'?
Explanation: The correct statement is 'SELECT game_name, release_date FROM game;'. Using '*' returns all fields, and the other options do not use proper SQL syntax.
Which SQL clause would you use to find games released between March 1, 2018 and March 31, 2022?
Explanation: The 'WHERE ... BETWEEN ... AND ...' clause correctly selects dates in range. 'GROUP BY' and 'ORDER BY' are used for grouping and sorting, not filtering by date. The 'WITHIN' term is not valid SQL.
Which SQL keyword would you use to show results starting with the highest value?
Explanation: 'DESC' is used with 'ORDER BY' to sort data in descending order. 'DOWN', 'END', and 'LAST' are not used for sorting results in SQL.
In a database setup with game, publisher, and developer tables, how are the tables typically linked?
Explanation: Tables are linked using primary keys from one table and foreign keys in another to relate the data. Identical field names alone do not ensure a relationship. Duplicate tables and password encryption serve other purposes.
In Microsoft Access, what must you do after writing your SQL query to view the returned results?
Explanation: Once the SQL query is written, you need to click 'run' to view results in Microsoft Access. Restarting the database, typing DISPLAY, or saving the table do not execute the query.