🛠️

SQL Full Course by Intellipaat

Jul 20, 2024

SQL Full Course by Intellipaat

Presented by: Multiple Experts

Agenda

  1. Introduction to Database
  2. Introduction to Database Management System (DBMS)
  3. SQL Concepts: Basic to Advanced
  4. Installing SQL Server
  5. Hands-On Session: Hacking Login Credentials and Prevention Methods
  6. Difference Between SQL and MySQL
  7. SQL Career Job and Salary Trends
  8. SQL Interview Questions and Answers

Lecture Highlights

Data and Database

  • Data: Facts related to an object; examples include age and video data.
  • Database: Systematic collection of data.
  • Examples: Telephone directories, contact list on mobiles, power consumption data, social media data.
  • Importance: Manages large amounts of data, ensures accuracy, ease of data uploading, data security, data integrity.

Database Management System (DBMS)

  • DBMS: Collection of programs to access, create, manipulate, and delete data in databases.
  • First DBMS: Developed in 1960 by Charles Bachmann (IDS: Integrated Data Store).
  • Evolution: DBMS functionalities enhance every year significantly.

Introduction to SQL

  • SQL: Standard language to deal with relational databases (create, read, update, delete records).
  • Stands for: Structured Query Language.
  • Relational Database: Type of database storing data points related to one another.
  • Flavors of SQL: MySQL, Oracle SQL, Microsoft SQL, Sybase, etc.
  • SQL Query Example: SELECT * FROM data1 WHERE age < 20;
  • Applications: Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), client-server architecture, three-tier architecture.

Basics of SQL Tables

  • Table: Database object comprised of rows and columns.
  • Fields (Columns): Specific data value, e.g., employee salary.
  • Records (Rows): Complete information of an entity, e.g., details of an employee named Annie.

SQL Data Types

  • Numeric Data: Integer, BigInt, SmallInt, TinyInt, Decimal.
  • Character Data: Char, Varchar (255), Text.
  • Date and Time Data: Date, Datetime formats.

Installing Microsoft SQL Server

  • Steps:
    1. Download SQL Server from Microsoft's official site.
    2. Choose Developer Edition.
    3. Install required features (Database Engine Services, etc.).
    4. Configure authentication, create accounts.
    5. Install SQL Server Management Studio (SSMS).
    6. Connect to Database Engine using SSMS.
  • Usage: Create, use, and drop databases using SQL commands.

SQL Constraints

  • NOT NULL: Ensures field contains a value.
  • DEFAULT: Provides a default value for a field if none specified.
  • UNIQUE: Ensures all values in a column are different.
  • PRIMARY KEY: Uniquely identifies each record, combination of NOT NULL and UNIQUE.

Creating Tables and Inserting Records

  • Create Table Syntax: CREATE TABLE employee ( e_id INT NOT NULL, e_name VARCHAR(20), e_salary INT, e_age INT, e_gender VARCHAR(20), e_dept VARCHAR(20), PRIMARY KEY (e_id) );
  • Insert Records Syntax: INSERT INTO employee VALUES (1, 'Sam', 95000, 45, 'Male', 'Operations');

Selecting Data

  • Simple Selection: SELECT e_name FROM employee;
  • Selecting Multiple Columns: SELECT e_name, e_salary FROM employee;
  • Selecting with Conditions (WHERE clause): SELECT * FROM employee WHERE e_gender = 'Female';

Filtering with AND, OR, NOT Operators

  • AND Operator: SELECT * FROM employee WHERE e_gender = 'Male' AND e_age < 30;
  • OR Operator: SELECT * FROM employee WHERE e_dept = 'Operations' OR e_dept = 'Analytics';
  • NOT Operator: SELECT * FROM employee WHERE NOT e_gender = 'Female';

LIKE and BETWEEN Operators

  • LIKE Operator: Extracts records matching a specified pattern. SELECT * FROM employee WHERE e_name LIKE 'J%';
  • BETWEEN Operator: Selects range of data values. SELECT * FROM employee WHERE e_salary BETWEEN 90000 AND 120000;

Basic SQL Functions

  • Aggregate Functions: MIN, MAX, COUNT, SUM, AVG. SELECT AVG(e_salary) FROM employee;

String Functions

  • LTRIM, LOWER, UPPER, REVERSE, SUBSTRING SELECT LOWER('SPARTA');

ORDER BY and TOP Clause

  • ORDER BY: Sort data in ascending or descending order. SELECT * FROM employee ORDER BY e_salary DESC;
  • TOP Clause: Fetch top N records from table. SELECT TOP 3 * FROM employee;

GROUP BY and HAVING Clauses

  • GROUP BY: Aggregate data by one or more columns.
  • HAVING: Apply conditions to groups. SELECT e_dept, AVG(e_salary) FROM employee GROUP BY e_dept HAVING AVG(e_salary) > 100000;

SQL Joins

  • INNER JOIN: Returns records with matching values in both tables. SELECT a.name, b.salary FROM employees a INNER JOIN salary b ON a.id = b.id;
  • LEFT JOIN: Returns records from the left table, and matched records from right table. SELECT a.name, b.salary FROM employees a LEFT JOIN salary b ON a.id = b.id;
  • RIGHT JOIN: Returns records from the right table, and matched records from left table. SELECT a.name, b.salary FROM employees a RIGHT JOIN salary b ON a.id = b.id;
  • FULL JOIN: Returns all records when there is a match in either table. SELECT a.name, b.salary FROM employees a FULL JOIN salary b ON a.id = b.id;

Temporary Tables

  • Temporary Table Creation: CREATE TABLE #temp_table (id INT, name VARCHAR(50));

SQL Injection

  • Definition: A method of manipulating SQL query to gain unauthorized access to a database.
  • Example: Passing OR '1' = '1'-- to bypass login.
  • Prevention: Use least privileges, hash passwords, employ third-party authentication.

Becoming an SQL Developer

  • Skills Required: SQL, programming, profiling, performance tuning.
  • Steps: Master SQL, get certified, build a portfolio, apply for jobs.

Career and Job Trends

  • Average Salary (USA): $72,282 per year
  • Average Salary (India): 6.5 LPA
  • Top Hiring Companies: Uber, Spotify, Netflix, Instagram, Twitter

Common SQL Interview Questions

  1. What is SQL?
  2. Explain different types of SQL commands.
  3. What are constraints? Explain default and unique constraints.
  4. How to find the second highest salary?
  5. Explain normalization and denormalization.
  6. What is a view in SQL?
  7. What is a stored procedure?
  8. Explain different JOINs in SQL.
  9. Difference between DELETE and TRUNCATE.
  10. Use of the INTERSECT operator.

This completes the key points from the SQL full course lecture by Intellipaat.