Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structured Query Language Chapter Three Part 3 – Inserts, Updates, Deletes.

Similar presentations


Presentation on theme: "Structured Query Language Chapter Three Part 3 – Inserts, Updates, Deletes."— Presentation transcript:

1 Structured Query Language Chapter Three Part 3 – Inserts, Updates, Deletes

2 2 Sample DB details PROJECT (ProjectID, Name, Department, MaxHours) PROJECT (ProjectID, Name, Department, MaxHours) EMPLOYEE (EmployeeNumber, Name, Phone, Department) EMPLOYEE (EmployeeNumber, Name, Phone, Department) ASSIGNMENT (ProjectID, EmployeeNum, HoursWorked) ASSIGNMENT (ProjectID, EmployeeNum, HoursWorked)

3 3

4 4 Referential Integrity Constraints for Sample DB ProjectID in ASSIGNMENT must exist in ProjectID in PROJECT ProjectID in ASSIGNMENT must exist in ProjectID in PROJECT EmployeeNum in ASSIGNMENT must exist in EmployeeNumber in EMPLOYEE EmployeeNum in ASSIGNMENT must exist in EmployeeNumber in EMPLOYEE

5 5 Business Rules for Sample DB If a PROJECT row is deleted, then all of the ASSIGNMENT rows that are connected to the delete PROJECT row also will be deleted. If a PROJECT row is deleted, then all of the ASSIGNMENT rows that are connected to the delete PROJECT row also will be deleted. If an EMPLOYEE row is deleted and that row is connected to any ASSIGNMENT, the EMPLOYEE row deletion will be disallowed. (It must first be re-assigned to another employee). If an EMPLOYEE row is deleted and that row is connected to any ASSIGNMENT, the EMPLOYEE row deletion will be disallowed. (It must first be re-assigned to another employee).

6 6 Modifying Data using SQL Insert Insert –Will add a new row in a table Update Update –Will update the data in a table that matches the specified criteria Delete Delete –Will delete the data in a table that matches the specified criteria

7 7 Adding Data: INSERT To add a row to an existing table, use the INSERT statement To add a row to an existing table, use the INSERT statement INSERT INTO Emp VALUES (91, ‘Smither’, 12); VALUES (91, ‘Smither’, 12); INSERT INTO Emp (EmpID, SalaryCode) VALUES (62, 11); VALUES (62, 11);

8 8 Changing Data Values: UPDATE To change the data values in an existing row (or set of rows) use the Update statement To change the data values in an existing row (or set of rows) use the Update statement UPDATE Emp SET Phone ‘791-555-1234’ WHERE EmpID = 29; UPDATE Emp SET DeptID = 44 WHERE EmpName LIKE ‘Kr%’;

9 9 Deleting Data: DELETE To delete a row or set of rows from a table using the DELETE statement To delete a row or set of rows from a table using the DELETE statement DELETE FROM Emp WHERE EmpID = 29; DELETE FROM Emp WHERE EmpName LIKE ‘Kr%’;


Download ppt "Structured Query Language Chapter Three Part 3 – Inserts, Updates, Deletes."

Similar presentations


Ads by Google