Database Reference
In-Depth Information
SELECT
[DISTINCT|ALL] {*|[column-name [AS new-name ], […..], ….}
FROM
table-name [alias], ………..
WHERE
condition
GROUP BY
column-list
HAVING condition
ORDER BY
column-list
Data Maintenance in SQL
As discussed thus far, SQL provides you with facilities to define the database objects
and to retrieve data once they are stored. But you know that the data in a database
keep changing all the time. If you have a customer database table, you need to add
more rows to the table as and when your organization gets new customers. If your
database has a table for customer orders, new rows must be added to this table
almost daily. Whenever changes are made to any of the rows in the customer or
order tables, you need to update the relevant rows. After a period of time, you may
want to delete the old orders and archive them on a separate storage medium. In
this case, you must be able to delete selected rows from the orders table. All of these
actions form part of data maintenance. Every database is subject to continual data
maintenance.
SQL provides three commands to perform data maintenance. Let us discuss each
command and understand it with some examples.
Adding Data
SQL Command
INSERT
Function
Add a new row to a table using the given values for the columns, or add one or
more rows to a table using the result of a query.
Examples
1. Add a new row into the EMPLOYEE table with the supplied values for all
columns.
INSERT INTO EMPLOYEE
VALUES (1234, 'Karolyn', 'Jones', '733 Jackie Lane, Baldwin Harbor, NY
11510', '516-223-8183', 'Senior VP', 95000, 'MGR')
2. Add a new row into the EMPLOYEE table with the supplied values for most
of the columns, leaving some column values as NULL.
INSERT INTO EMPLOYEE
VALUES (3344, 'Robert', 'Moses', '142 Crestview Drive, Long Branch, NJ
08835', NULL, NULL, 40000, 'STF')
3. Add new rows into the MANAGER,
selecting managers from the
EMPLOYEE table.
Search WWH ::




Custom Search