|
Syntax:
INSERT INTO relationName VALUES ( .... ) or INSERT INTO relationName(attributeList) VALUES ( .... ) |
You can omit the list of attributes.
Example:
INSERT INTO employee VALUES ('Richard', 'K', 'Marini', '222669999', '30-Dec-52', '98 Oak Street, Katy, TX', 'M', 37000, '987654321', 4); |
You must provide a list of attributes.
INSERT INTO employee(fname, lname, ssn) VALUES ('Richard', 'Marini', '222669999'); |
Syntax:
INSERT INTO relationName (SELECT ...) |
Example: expense report for each department:
CREATE TABLE dept_info ( DName CHAR(20), No_Emps INTEGER, Tot_Sal DECIMAL(9,2) ); |
|
|
DELETE FROM relationName [WHERE tuple-boolean-condition] |
Delete the employee 'John Smith'
DELETE FROM employee WHERE fname = 'John' AND lname = 'Smith'; |
Delete all employees from the 'Research' department
DELETE FROM employee WHERE dno IN (SELECT dnumber FROM department WHERE dname = 'Research') |
Delete all employees from the 'Research' department have more than 2 dependents
DELETE FROM employee WHERE dno IN (SELECT dnumber FROM department WHERE dname = 'Research') AND ssn IN (SELECT essn FROM dependent GROUP BY essn HAVING COUNT(name) > 2) |
UPDATE relationName SET attributeName = expression [WHERE tuple-boolean-condition] |
Change the address of employee 'John Smith' to '123 Pike Lane, Austin, TX'
UPDATE employee SET address = '123 Pike Lane, Austin, TX' WHERE fname = 'John' AND lname = 'Smith'; |
Give all employees in the 'Research' department a 10% raise
UPDATE employee SET salary = 1.1 * salary WHERE dno IN (SELECT dnumber FROM department WHERE dname = 'Research') |
See: /home/cs377001/demo/SQL-DML |