25 Lecture

CS403

Midterm & Final Term Short Notes

Rules of SQL Format

The rules of SQL format are a set of guidelines that should be followed when writing SQL queries to ensure consistency and readability. These include using proper indentation, using all caps for SQL keywords, using meaningful aliases for tables


Important Mcq's
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is the recommended way to format SQL keywords in a query? a) All lowercase b) All uppercase c) Capitalize only the first letter d) It doesn't matter Answer: b) All uppercase What is the recommended way to format table and column aliases in a query? a) Use short, cryptic aliases to save space b) Use long, descriptive aliases to make the code more readable c) Don't use aliases at all d) It doesn't matter Answer: b) Use long, descriptive aliases to make the code more readable What is the recommended way to format subqueries in a query? a) Include them within the main query on a single line b) Break them out into separate, indented lines c) Don't use subqueries d) It doesn't matter Answer: b) Break them out into separate, indented lines What is the recommended way to format the SELECT clause in a query? a) Include all columns on a single line b) Break the columns out into separate lines c) Use a combination of both, depending on the length of the query d) It doesn't matter Answer: b) Break the columns out into separate lines What is the recommended way to format the FROM clause in a query? a) Include all tables on a single line b) Break the tables out into separate lines c) Use a combination of both, depending on the length of the query d) It doesn't matter Answer: b) Break the tables out into separate lines What is the recommended way to format the WHERE clause in a query? a) Include all conditions on a single line b) Break the conditions out into separate, indented lines c) Don't use the WHERE clause d) It doesn't matter Answer: b) Break the conditions out into separate, indented lines What is the recommended way to format comments in SQL code? a) Use single-line comments starting with # b) Use multi-line comments starting with /* c) Use both single-line and multi-line comments, depending on the context d) It doesn't matter Answer: c) Use both single-line and multi-line comments, depending on the context What is the recommended way to format keywords in a query that are not SQL keywords? a) Use all lowercase b) Use all uppercase c) Capitalize only the first letter d) It doesn't matter Answer: a) Use all lowercase What is the recommended way to format a JOIN clause in a query? a) Include all tables on a single line b) Break the tables out into separate lines c) Use a combination of both, depending on the length of the query d) It doesn't matter Answer: b) Break the tables out into separate lines What is the recommended way to format a GROUP BY clause in a query? a) Include all columns on a single line b) Break the columns out into separate lines c) Use a combination of both, depending on the length of the query d) It doesn't matter Answer: b) Break the columns out into separate lines


Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included

Download PDF
  1. What is SQL? Explain the different components of SQL. Answer: SQL stands for Structured Query Language, it is used to manage relational databases. The different components of SQL include Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), and Transaction Control Language (TCL). Define the term ‘Schema’ in SQL. Answer: A Schema in SQL is a logical container for a database that allows users to logically group the objects such as tables, views, indexes, etc. It is a collection of database objects, including tables, indexes, and views. What is a subquery in SQL? Answer: A subquery is a query that is nested inside another SQL statement. It is also known as an inner query, and it is usually placed inside a parenthesis. What is a view in SQL? Answer: A view is a virtual table that is based on the result of an SQL statement. Views are not physical tables; they are derived from one or more tables or views. What is a trigger in SQL? Answer: A trigger in SQL is a set of SQL statements that are executed automatically in response to a specified event. A trigger can be used to implement a variety of actions, such as inserting, updating, or deleting data in a table. What is normalization in SQL? Answer: Normalization in SQL is the process of organizing data in a database so that data is stored in the most efficient way possible. The main objective of normalization is to minimize data redundancy and improve data integrity. What is a primary key in SQL? Answer: A primary key in SQL is a column or set of columns in a table that uniquely identifies each row in the table. The primary key can be a single column or a combination of columns. What is a foreign key in SQL? Answer: A foreign key in SQL is a column or set of columns in a table that refers to the primary key of another table. It is used to establish a relationship between two tables. What is the difference between WHERE and HAVING clause in SQL? Answer: The WHERE clause is used to filter records before they are grouped, while the HAVING clause is used to filter records after they have been grouped. What is an index in SQL? Answer: An index in SQL is a data structure that is used to improve the speed of data retrieval operations on a table. It is similar to an index in a book that allows you to quickly find information. An index is created on one or more columns of a table.

SQL (Structured Query Language) is a standardized language used to manage relational databases. To write effective SQL queries, it is important to follow certain rules of SQL format.
  1. SQL statements should be terminated with a semicolon (;).
  2. Keywords and function names should be written in uppercase letters.
  3. Table names, column names, and aliases should be written in lowercase letters.
  4. String values should be enclosed in single quotes (' ').
  5. Comments can be added using double dashes (--).
  6. White spaces, such as tabs and line breaks, can be added for better readability.
  7. SQL statements can span multiple lines.
  8. When using multiple SQL statements, they should be separated by a semicolon (;).
  9. Dates should be formatted as YYYY-MM-DD or as a timestamp.
  10. Avoid using reserved keywords as table or column names.
By following these rules, it becomes easier to write and understand SQL queries. Additionally, adhering to a standard SQL format makes it easier for other developers to read and modify the code. SQL (Structured Query Language) is a standardized language used to manage relational databases. To write effective SQL queries, it is important to follow certain rules of SQL format.
  1. SQL statements should be terminated with a semicolon (;).
  2. Keywords and function names should be written in uppercase letters.
  3. Table names, column names, and aliases should be written in lowercase letters.
  4. String values should be enclosed in single quotes (' ').
  5. Comments can be added using double dashes (--).
  6. White spaces, such as tabs and line breaks, can be added for better readability.
  7. SQL statements can span multiple lines.
  8. When using multiple SQL statements, they should be separated by a semicolon (;).
  9. Dates should be formatted as YYYY-MM-DD or as a timestamp.
  10. Avoid using reserved keywords as table or column names.
By following these rules, it becomes easier to write and understand SQL queries. Additionally, adhering to a standard SQL format makes it easier for other developers to read and modify the code.