0% found this document useful (0 votes)
11 views6 pages

NUT Removed

My SQL queries

Uploaded by

Prateek Tiwari
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)
11 views6 pages

NUT Removed

My SQL queries

Uploaded by

Prateek Tiwari
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
You are on page 1/ 6

SQL QUERIES

PROGRAM-1

1. Create Employee Table and Insert Records


SOURCE CODE:

-- 1. Create the 'employees' table


CREATE TABLE employees (
emp_id INT PRIMARY KEY,
emp_name VARCHAR(50),
department VARCHAR(30),
salary INT
);

-- 2. Insert records into the 'employees' table


INSERT INTO employees (emp_id, emp_name, department, salary) VALUES
(1, 'Ravi Kumar', 'HR', 50000),
(2, 'Aarti Sharma', 'Finance', 60000),
(3, 'Suresh Gupta', 'IT', 75000), (4,
'Anita Verma', 'Finance', 55000);

-- 3. Fetch all records from the 'employees' table to confirm the insertion
SELECT * FROM employees;

17
PROGRAM-2

Create a Students Table and Insert Data

SOURCE CODE:

-- 1. Create the 'students' table


CREATE TABLE students (
student_id INT PRIMARY KEY,
student_name VARCHAR(50),
marks INT,
course VARCHAR(30)
);

-- 2. Insert records into the 'students' table


INSERT INTO students (student_id, student_name, marks, course)
VALUES
(101, 'Rahul Sharma', 95, 'Physics'),
(102, 'Anjali Mehta', 88, 'Mathematics'),
(103, 'Rohit Verma', 92, 'Chemistry'),
(104, 'Priya Singh', 80, 'Biology'), (105,
'Amit Kumar', 70, 'History');

-- 3. Fetch students who scored more than 80 marks


SELECT student_id, student_name, marks
FROM students
WHERE marks > 80;
PROGRAM – 3

Update Employee Salary in Finance Department

SOURCE CODE:
-- 1. Create the 'employees' table
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
emp_name VARCHAR(50),
department VARCHAR(30),
salary INT
);

-- 2. Insert records into the 'employees' table


INSERT INTO employees (emp_id, emp_name, department, salary) VALUES
(1, 'Ravi Kumar', 'HR', 50000),
(2, 'Aarti Sharma', 'Finance', 60000), (3,
'Suresh Gupta', 'IT', 75000);

-- 3. Update salary of employees in the 'Finance' department


UPDATE employees
SET salary = salary + 5000
WHERE department = 'Finance';

-- 4. Fetch all records from the 'employees' table to confirm the update
SELECT *
FROM employees;

3
PROGRAM – 4

Delete a Student Record.

SOURCE CODE:
-- 1. Create the 'students' table
CREATE TABLE students (
student_id INT PRIMARY KEY,
student_name VARCHAR(50),
marks INT,
course VARCHAR(30)
);

-- 2. Insert records into the 'students' table


INSERT INTO students (student_id, student_name, marks, course)
VALUES
(101, 'Rahul Sharma', 95, 'Physics'),
(102, 'Anjali Mehta', 88, 'Mathematics'), (103,
'Rohit Verma', 92, 'Chemistry');

-- 3. Delete the record of the student with 'student_id = 101'


DELETE FROM students
WHERE student_id = 101;

-- 4. Fetch all remaining students after deletion


SELECT *
FROM students;
PROGRAM – 5
Join Students with Courses.

SOURCE CODE:
-- 1. Create the 'students' table
CREATE TABLE students (
student_id INT PRIMARY KEY,
student_name VARCHAR(50),
course_id INT
);

-- 2. Create the 'courses' table


CREATE TABLE courses ( course_id
INT PRIMARY KEY,
course_name VARCHAR(50)
);

-- 3. Insert records into the 'students' table


INSERT INTO students (student_id, student_name, course_id)
VALUES
(101, 'Rahul Sharma', 1),
(102, 'Anjali Mehta', 2), (103,
'Rohit Verma', 1);

-- 4. Insert records into the 'courses' table


INSERT INTO courses (course_id, course_name)
VALUES
(1, 'Physics'), (2,
'Mathematics');

-- 5. Perform a JOIN between 'students' and 'courses'


SELECT students.student_name, courses.course_name
FROM students
JOIN courses
ON students.course_id = courses.course_id;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy