0% found this document useful (0 votes)
4 views2 pages

SQL Queries for Student and Employee Management

The document outlines SQL commands for creating and managing three tables: Student, Employee, and Product, along with a Login table. It includes operations such as inserting records, querying data based on conditions, updating employee salaries, and calculating totals and averages. The document serves as a guide for basic database operations and queries in SQL.

Uploaded by

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

SQL Queries for Student and Employee Management

The document outlines SQL commands for creating and managing three tables: Student, Employee, and Product, along with a Login table. It includes operations such as inserting records, querying data based on conditions, updating employee salaries, and calculating totals and averages. The document serves as a guide for basic database operations and queries in SQL.

Uploaded by

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

1.

Create Student Table & Display Records


CREATE TABLE Student (
RollNo INT PRIMARY KEY,
Name VARCHAR(50),
Class INT,
Marks INT
);

INSERT INTO Student VALUES


(1, 'Amit', 12, 85),
(2, 'Riya', 12, 92),
(3, 'Suresh', 12, 78);

SELECT * FROM Student;

2. Display Students Scoring More Than 80


SELECT Name, Marks FROM Student
WHERE Marks > 80;

3. Sort Students by Marks (Descending)


SELECT * FROM Student
ORDER BY Marks DESC;

4. Count Total Students


SELECT COUNT(*) AS Total_Students FROM Student;

5. Create Employee Table & Display Name and Salary


CREATE TABLE Employee (
EmpID INT PRIMARY KEY,
EmpName VARCHAR(50),
Salary INT,
Department VARCHAR(30)
);

INSERT INTO Employee VALUES


(101, 'Rahul', 45000, 'Sales'),
(102, 'Sneha', 52000, 'HR'),
(103, 'Arjun', 47000, 'IT');

SELECT EmpName, Salary FROM Employee;

6. Display Employees Working in HR


SELECT EmpName FROM Employee
WHERE Department = 'HR';

7. Increase Salary of IT Employees by 10%


UPDATE Employee
SET Salary = Salary * 1.10
WHERE Department = 'IT';

SELECT * FROM Employee;


8. Create Product Table & Show Products Cheaper Than 500
CREATE TABLE Product (
ProductID INT PRIMARY KEY,
ProductName VARCHAR(50),
Price INT
);

INSERT INTO Product VALUES


(1, 'Pen', 20),
(2, 'Notebook', 70),
(3, 'Bag', 850),
(4, 'Bottle', 120);

SELECT ProductName, Price FROM Product


WHERE Price < 500;

9. Display Total & Average Price of Products


SELECT SUM(Price) AS Total_Price,
AVG(Price) AS Average_Price
FROM Product;

10. Create Login Table & Search by Username


CREATE TABLE Login (
UserID INT PRIMARY KEY,
Username VARCHAR(50),
Password VARCHAR(50)
);

INSERT INTO Login VALUES


(1, 'keshav', 'pass123'),
(2, 'neha', 'love2024');

SELECT * FROM Login


WHERE Username = 'keshav';

You might also like