SQL - P2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Relational Data Base Management System

SQL-02

1
Inserting Data
Inserting a record
SQL> INSERT INTO vehicleparts(cost, part_no, disc, price)
VALUES(100,'p223','honda engine',120.00);

Inserting multiple records


SQL> INSERT INTO vehicleparts(cost,part_no,disc,price)
VALUES(100,'p111','honda engine',120.00),
(500,'p333','BMW engine',600.00),
(200,'p444','Nissan engine',220.00);

• Separate values with commas.


• Use the DESCRIBE command to show order and type of
columns.
• Each value must match the data type of targeted column.
• Enclose CHAR and DATE values in single quotes .
2
Inserting DATE Values
Default format for entering dates:
‘DD-MON-YY’

Enter a new employee ‘SMITH’.

SQL>INSERT INTO EMP


(EMPNO, ENAME, HIREDATE)
VALUES (7963, ‘SMITH’, ’07-APR-87’);

To automatically enter today’s date and time

SQL>INSERT INTO EMP


(EMPNO, ENAME, HIREDATE)
VALUES (7600, ‘SMITH’, GETDATE());
3
Updating data
• Used to update records in a table.
• Allows to change the values in one or more columns
of a single row or multiple rows.

SQL> UPDATE vehicleparts


SET cost = 200.00
WHERE part_no = 'P222';

4
Updating Multiple Rows in Multiple
Columns
SQL> UPDATE vehicleparts
SET
cost = 250.00,price=450
WHERE
part_no = 'P223';’;

5
Deleting data
• You cannot delete a part of rows.
• Instead, update the columns to NULL.
The WHERE clause determines which rows are to be
deleted.
If you forget the WHERE clause you will delete all
the rows.

SQL>DELETE from vehicleparts


WHERE part_no='p223'

6
Delete and limit
• Limit the number of row to delete.
• Must use the order by to clause to order records
before delete.

• SQL>DELETE FROM vehicleparts


ORDER BY part_no
LIMIT 5;

7
Deleting all records

• Use Truncate or Delete.


• delete from vehicleaprts;
• Or Truncate table vehicleparts;

You might also like