Data manipulation language (DML) statements query or manipulate data in existing schema objects. They enable you to:
DML statements are the most frequently used SQL statements.
You can use the SQL INSERT statement to add a row of data to a table. The data inserted must be valid for the data type and size of each column of the table.
Example: Using the INSERT Statement shows how to use INSERT to add a row to the employees table. In the first INSERT statement, values are inserted into all columns in a row of the table. When you insert data into the columns, you must provide data values that are valid for the data type and size of the column.
In the second INSERT statement, values are inserted only into the specified columns of the table and the remaining columns are set to NULL. If the those remaining columns had been specified with a NOT NULL constraint for the table, an error would have been raised. For information on constraints, see "Managing Tables" and Column Constraints.
Using the INSERT Statement
-- the following inserts data for all the columns in a row INSERT INTO employees VALUES (300, 'Enrique', 'Belden', 'enrique.belden', '555.111.2222', '01-AUG-05', 'AC_MGR', 9000, .1, 101, 110); -- the following inserts data into the columns specified by name -- NULLs are inserted in those columns not explicitly named INSERT INTO employees (employee_id, last_name, email, hire_date, job_id, salary) VALUES (301, 'Doe', 'john.doe', '31-AUG-05', 'SH_CLERK', 2400); -- the following shows the rows were inserted beginning with 300 SELECT employee_id, last_name FROM employees WHERE employee_id >= 300;
|
See Also:
|
You can use the SQL UPDATE statement to update data in a row of a table. The updated data must be valid for the data type and size of each column of the table.
Example: Using the UPDATE Statement shows how to use UPDATE to update data in the employees table. Note the use of the use of multiplication operator * to calculate a new salary. For information on arithmetic operators, See "Using Arithmetic Operators".
Using the UPDATE Statement
SELECT salary FROM employees WHERE employee_id = 301; -- update the salary for employee 301, multiply the salary by 105% UPDATE employees SET salary = salary * 1.05 WHERE employee_id = 301; -- the following should show a change in salary SELECT salary FROM employees WHERE employee_id = 301;
|
See Also:
|
With the SQL DELETE statement you can delete all or specific rows in a table.
When you delete all the rows in a table, the empty table still exists. If you want to remove the entire table from the database, use the SQL DROP statement. See "Dropping a Table With SQL".
Example: Using the DELETE Statement shows how to use DELETE to delete selected rows in the employees table. Note the use of the WHERE clause. Without that clause, all the rows would be deleted.
Using the DELETE Statement
DELETE FROM employees WHERE employee_id = 300 OR employee_id = 301; -- the following query should not find any records SELECT * FROM employees WHERE employee_id = 300 OR employee_id = 301;
If you accidentally delete rows, you can restore the rows with the ROLLBACK statement. See "Rolling Back a Transaction".
|
See Also:
|