0% found this document useful (0 votes)
19 views3 pages

SQL Topics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

SQL Topics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Topic Description

DDL Data Definition Language (CREATE, DROP, ALTER)

DML Data Manipulation Language (INSERT, UPDATE, DELETE)

DQL Data Query Language (SELECT)

DCL Data Control Language (GRANT, REVOKE)

TCL Transaction Control Language (COMMIT, ROLLBACK)

Joins INNER, LEFT, RIGHT, FULL, SELF

Constraints PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL

Functions COUNT, SUM, AVG, MAX, MIN

Clauses WHERE, GROUP BY, HAVING, ORDER BY

Subqueries Nested queries inside other queries

Views Virtual table based on result of a query

Index Speeds up data retrieval

Normalization Reduces data redundancy

Employee table
Department
Projects
Employee_Projects

CREATE TABLE Employees (


EmpID INT PRIMARY KEY,
Name VARCHAR(50),
Department VARCHAR2(50),
Salary INT,
Age INT
);

CREATE TABLE Departments (


DeptID INT PRIMARY KEY,
DeptName VARCHAR(50)
);

CREATE TABLE Projects (


ProjectID INT PRIMARY KEY,
ProjectName VARCHAR(100),
DeptID INT,
FOREIGN KEY (DeptID) REFERENCES Departments(DeptID)
);

CREATE TABLE Employee_Project (


EmpID INT,
ProjectID INT,
PRIMARY KEY (EmpID, ProjectID),
FOREIGN KEY (EmpID) REFERENCES Employees(EmpID),
FOREIGN KEY (ProjectID) REFERENCES Projects(ProjectID)
);

-- Employees
INSERT INTO Employees (EmpID, Name, Department, Salary, Age) VALUES
(1, 'Ravi Kumar', 'HR', 50000, 25),
(2, 'Sneha Sharma', 'IT', 70000, 28),
(3, 'Amit Verma', 'IT', 60000, 32),
(4, 'Neha Singh', 'Finance', 80000, 30),
(5, 'Manoj Patil', 'HR', 52000, 26),
(6, 'Pooja Reddy', 'IT', 75000, 35),
(7, 'Siddharth Mehra', 'Finance', 67000, 29),
(8, 'Deepa Nair', 'Sales', 55000, 31),
(9, 'Vikram Joshi', 'Sales', 54000, 30),
(10, 'Anjali Desai', 'HR', 51000, 27);

-- Departments
INSERT INTO Departments (DeptID, DeptName) VALUES
(1, 'HR'),
(2, 'IT'),
(3, 'Finance'),
(4, 'Sales'),
(5, 'Marketing');

-- Projects
INSERT INTO Projects (ProjectID, ProjectName, DeptID) VALUES
(101, 'CRM System Upgrade', 2),
(102, 'Campus Hiring Program', 1),
(103, 'Annual Budget Planning', 3),
(104, 'New Product Campaign', 4),
(105, 'Digital Marketing Blitz', 5);

-- Employee_Project
INSERT INTO Employee_Project (EmpID, ProjectID) VALUES
(1, 102),
(2, 101),
(3, 101),
(4, 103),
(5, 102),
(6, 101),
(7, 103),
(8, 104),
(9, 104),
(10, 102);

mysql -u root -p

alter table employees add email varchar(100);


ALTER TABLE Employees ADD Email VARCHAR2(100);

add a NOT NULL constarints on name


alter table employees modify name varchar(50) NOT NULL;
add default value to salary
alter table employees modify salary DEFAULT 50000;

modify department column to increase its size


alter table department MODIFY deptname varchar(100);

add unique constraints to name


alter table employees modify name varchar(50) unique;
alter table employees add constraints unique_name UNIQUE(name);

drop the unique constraints on name


alter table employees drop constraints unique_name;

You might also like