Introduction

Many students or even experience people ask for quick read or you can say it cheatlist specially for SQL. As it is the base technology and every interview have questions on SQL. I am trying to collate all important points and concept at one place.

SQL Keys

SQL Commands

  1. Data Definition Language (DDL) Commands
    • CREATE: Creates a new table or view or other objects.
    • ALTER: Modifies an existing database object, such as a table.
    • DROP: Deletes an entire table or view or other objects.
    • TRUNCATE: Removes all rows from a table.
  2. Data Manipulation Language (DML) Commands
    • INSERT: Adds new rows to a table.
    • UPDATE: Modifies existing data within a table.
    • DELETE: Removes rows from a table
  3. Data Query Language (DQL) Commands
    • SELECT: Retrieves certain records from one or more tables
  4. Data Control Language (DCL) Commands
    • GRANT: Gives users access privileges to the database.
    • REVOKE: Removes access privileges given to the user.
  5. Transaction Control Language (TCL) Commands
    • COMMIT: Saves all changes made in the current transaction.
    • ROLLBACK: Undoes all changes made in the current transaction.
    • SAVEPOINT: Sets a point within a transaction to which you can later roll back.

SQL Constraints

  1. Learn what constraints are and why they are important.
  2. Understand their role in maintaining data integrity.
  3. Explore some real-life examples how constraints can be implemented.
  4. SQL Constraints are as:
    • NOT NULL: Ensures that a column cannot have a NULL value.
    • UNIQUE: Guarantees that all values in a column are different.
    • PRIMARY KEY: A combination of NOT NULL and UNIQUE, uniquely identifies each row in a table.
    • FOREIGN KEY: Ensures referential integrity by linking a column or a group of columns to a PRIMARY KEY in another table.
    • CHECK: Enforces a specific rule on each row in a table, ensuring that certain conditions are true or false.
    • DEFAULT: Set a default value for a column when no value is given to that column

SQL Clauses/Queries

  1. Practice simple queries focusing on specific clauses.
  2. Here are the SQL Clauses:
    • SELECT: Specifies the columns to be retrieved from the database.
    • FROM: Indicates the table(s) from which data is to be selected.
    • WHERE: Filters the rows returned by the query based on specified conditions.
    • GROUP BY: Groups rows sharing a property so that aggregate functions can be applied to each group.
    • HAVING: Filters groups defined by the GROUP BY clause based on specified conditions.
    • ORDER BY: Sorts the results of a query in ascending or descending order based on specified columns.
  3. Understand SQL Clauses Execution Order as they are executed in a specific order within a query.

T-SQL Fundamentals

Follow below points to navigate T-SQL fundamentals:

SQL Joins

SQL Functions

  1. Aggregate Functions: Operate on a set of values.
    • COUNT(): Counts the number of rows.
    • SUM(): Calculates the sum of values.
    • AVG(): Calculates the average of values.
    • MIN(): Retrieves the minimum value.
    • MAX(): Retrieves the maximum value.
  2. Scalar Functions: Operate on a single value
    • UPPER(): Converts a string to uppercase.
    • LOWER(): Converts a string to lowercase.
    • LEN() or LENGTH(): Returns the length of a string.
    • CONCAT(): Concatenates two or more strings.
    • SUBSTRING(): Extracts a portion of a string.
  3. User-defined Functions: Created by users to perform specific operations, not available using built-in SQL functions.

SQL Exception Handling

SQL Indexes

  1. Improve the speed of data retrieval operations on a database table by providing quick access to rows based on the index keys.
  2. Identify scenarios where using indexes is beneficial.
  3. Familiarize yourself with types of SQL indexes:
    • Clustered Index: Organizes the actual data rows within a table in a specific, sorted order based on the index key.
    • Non-Clustered Index: Creates a separate structure holding a sorted list of key values, along with pointers to the corresponding rows in the table.
  4. Regularly revisit and refine your indexing strategy based on evolving database requirements and usage

SQL Views

  1. A virtual table created by a query that selects data from one or more tables, providing a customizable and reusable snapshot of data.
  2. Create simple views to retrieve columns from one or more tables.
  3. Understand how to update data through views.
  4. Be aware of restrictions on updating views based on complex queries.
  5. Use ALTER VIEW statement to modify existing views.
  6. Understand how changes in tables affect views.
  7. Use DROP VIEW to remove unnecessary views.
  8. Be cautious about dependencies before dropping views.

SQL Stored Procedures

Know various types of stored procedures in SQL Server:

  1. System Defined Stored Procedure: Document the available system procedures, their purposes, and any specific requirements for their usage.
  2. User-defined Stored Procedure: Identify the business requirements that can be fulfilled using user-defined stored procedures.
  3. CLR Stored Procedure: Learn about CLR integration and how it allows you to use .NET languages to create stored procedures.
  4. Extended Stored Procedure: Understand the concept of extended stored procedures, which are specific to Microsoft SQL Server

SQL Transaction Control

Familiarize yourself with the concept of transactions, the ACID properties (Atomicity, Consistency, Isolation, Durability), and how they ensure data integrity.

  1. BEGIN TRANSACTION Command: Understand how to initiate a transaction using the BEGIN TRANSACTION command.
  2. SET TRANSACTION Command: Learn this to configure properties like isolation level and other transaction-specific settings.
  3. COMMIT Command: Understand the purpose and usage of COMMIT command to make the changes within a transaction permanent.
  4. ROLLBACK Command: Learn to undo changes made within a transaction.
  5. SAVEPOINT Command: Understand how to set intermediate points within a transaction.

SQL Triggers

SQL Cursors