SQL-tutorial
SQL-tutorial copied to clipboard
SQL assignment that covers the basic usage of the INSERT, UPDATE, and DELETE statements.
Scenario:
Assume you have a database named Company
with a table named Employees
. The Employees
table has the following columns:
-
EmployeeID
(integer, primary key) -
FirstName
(varchar) -
LastName
(varchar) -
Department
(varchar) -
Salary
(numeric)
Tasks:
-
Insert Data:
- Insert a new employee with the following details:
- EmployeeID: 101
- FirstName: 'John'
- LastName: 'Doe'
- Department: 'IT'
- Salary: 60000
- Insert a new employee with the following details:
-
Update Data:
- Update the salary of the employee with EmployeeID 101 to 65000.
-
Delete Data:
- Delete the employee with EmployeeID 101 from the
Employees
table.
- Delete the employee with EmployeeID 101 from the
Submission Guidelines:
- Create a SQL script that includes the necessary INSERT, UPDATE, and DELETE statements.
- Include comments to explain each statement.
- Assume that the database and table already exist.
Sample Solution:
-- Task 1: Insert Data
INSERT INTO Employees (EmployeeID, FirstName, LastName, Department, Salary)
VALUES (101, 'John', 'Doe', 'IT', 60000);
-- Task 2: Update Data
UPDATE Employees
SET Salary = 65000
WHERE EmployeeID = 101;
-- Task 3: Delete Data
DELETE FROM Employees
WHERE EmployeeID = 101;