type of testing

Search

Total Views

Total Views:

sql


SQL 

What is SQL?

SQL (Structured Query Language) is a standard programming language used to interact with relational databases. It is used to store, retrieve, update, and delete data
SQL is also used to create and modify database structures such as tables, views, and indexes.
Example: 
SELECT * FROM Employees; 
This query retrieves all the records from the Employees table.
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
What is a Database?
It allows users to efficiently store, retrieve, update, and manage data. 
Databases are used to handle large amounts of information in various applications such as websites, business systems, and applications.

Example: A customer database in an e-commerce website may store customer details like name, email, contact number, and purchase history.

  1. Create a Database
  2. Create Student table
  3. Insert Data into Student Table
  4. Select/ Retrieve data from table
  5. Where (Filter record based on condition) 
  6. DISTINCT (Display Unique Record from a table)

Comprehensive

DDL DML DQL TCL DCL
CREATE INSERT SELECT COMMIT GRANT
ALTER UPDATE ROLLBACK REVOKE
DROP DELETE SAVE POINT
TRUNCATE
RENAME
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
What is Primary Key?
A Primary Key is a column or a combination of columns in a table that uniquely identifies
each row in that table. It does not allow NULL values and must always contain unique
values.
Key Features: 
  • Uniquely identifies each record 
  • Cannot have duplicate values
  • Cannot contain NULL values
  • Only one primary key is allowed per table
Example:
This is a SQL Data Definition Language (DDL) statement. 
CREATE TABLE Employee (
                EmployeeID INT PRIMARY KEY, 
                Name VARCHAR (50), 
                Age INT
);

Here, EmployeeID is the primary key that uniquely identifies each employee.
一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一一
What is Foreign Key?
A Foreign Key is a column or combination of columns in one table that refers to the Primary Key in another table. 
It is used to create a relationship between two tables and enforce referential integrity. 
Key Features:
  • Establishes a relationship between two tables
  • Can contain duplicate values
  • Can accept NULL values 
  • Helps maintain data consistency
Example

Parent table

    CREATE TABLE Department (         
                    DeptID INT PRIMARY KEY,        
                    DeptName VARCHAR (50)
    );

Child Table with Foreign Key

CREATE TABLE Employee (
                EmployeeID INT PRIMARY KEY, 
                Name VARCHAR (50), 
                Age INT
                DeptID INT,
                FOREIGN KEY (DeptID) REFERENCES Department (DeptID)    
);

UNIQUE Key — simple and precise explanation

A UNIQUE key is a database rule (constraint) that does not allow duplicate values in a column (or a group of columns).

What it does

  • Every non-NULL value in the column must be different

  • It prevents duplicates

  • It allows NULL (usually only one NULL, depending on the database)

Key points (no confusion)

  • Ensures uniqueness of data

  • NULL is allowed (unlike PRIMARY KEY)

  • You can have multiple UNIQUE keys in one table

  • Used to protect important data like email, phone number, username

Example

CREATE TABLE Users (
                  UserID INT PRIMARY KEY,
                  Email VARCHAR(100) UNIQUE    
);




Comments

🌟🌟🌟🌟☆ Great platform with helpful onboarding! Some areas could be streamlined, but overall a very positive experience.