0% found this document useful (0 votes)
16 views6 pages

DBMS Experimentdbms-4

The document discusses various SQL data manipulation language (DML) commands like INSERT, SELECT, UPDATE, and DELETE. It provides the syntax and examples for each command, and compares the difference between DELETE and DROP commands.

Uploaded by

Deepak Swami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

DBMS Experimentdbms-4

The document discusses various SQL data manipulation language (DML) commands like INSERT, SELECT, UPDATE, and DELETE. It provides the syntax and examples for each command, and compares the difference between DELETE and DROP commands.

Uploaded by

Deepak Swami
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

EXPERIMENT-4

Aim: To study the various DML commands and implement them on the database.

Tools/ Apparatus:
HARDWARE REQUIREMENTS:

INTEL PENTIUM DUAL CORE

80GB HDD

512MB DDR

SOFTWARE REQUIREMENTS:

ORACLE 10g

Procedure:

To study the various DML commands and implement them on the database.

DML COMMANDS
DML commands are the most frequently used SQL commands and is used to query and
manipulate the existing database objects. Some of the commands are Insert, Select, Update, Delete.
Insert Command This is used to add one or more rows to a table. The values are separated by
commas and the data types char and date are enclosed in apostrophes. The values must be entered in
the same order as they are defined.
Select Commands It is used to retrieve information from the table. It is generally referred to as
querying the table. We can either display all columns in a table or only specify column from the
table.
Update Command It is used to alter the column values in a table. A single column may be updated or
more than one column could be updated.
Delete command After inserting row in a table we can also delete them if required. The delete
command consists of a from clause followed by an optional where clause.

1. SQL SELECT Statement-

In SQL, the SELECT statement is used to query or retrieve data from a table in the database. The
returns data is stored in a table, and the result table is known as result-set.

Syntax

1. SELECT <column1>, <column2>, …


FROM table_name;
Use the following syntax to select all the fields available in the table:

SELECT * FROM <table_name>;

To fetch the EMP_ID of all the employees, use the following query:

Ex. SELECT EMP_ID FROM EMPLOYEE;

SELECT EMP_NAME, SALARY FROM EMPLOYEE;

2. SQL INSERT Statement-

The SQL INSERT statement is used to insert a single or multiple data in a table. In SQL, you can insert
the data in two ways:

1. Without specifying column name

2.By specifying column name

1. Without specifying column name

If you want to specify all column values, you can specify or ignore the column values.

Syntax

INSERT INTO <TABLE_NAME>

VALUES (value1, value2, value 3, …. Value N);

Ex. INSERT INTO EMP VALUES (1, 'Kriti', 'Sikar', 60000);

2.By specifying column name-

To insert partial column values, you must have to specify the column names.

Syntax

INSERT INTO <TABLE_NAME>

[(col1, col2, col3,…. col N)]

VALUES (value1, value2, value 3, …. Value N);

Ex. INSERT INTO EMPLOYEE (EMP_ID, EMP_NAME, AGE) VALUES (7, 'Jack', 40);
3. SQL Update Statement-

The SQL UPDATE statement is used to modify the data that is already in the database. The condition
in the WHERE clause decides that which row is to be updated.

Syntax

UPDATE <table_name>

SET column1 = value1, column2 = value2, ...

WHERE <condition>;

- Updating single record-

Ex. Update the column EMP_NAME and set the value to 'Emma' in the row where SALARY is
500000.

Syntax

UPDATE <table_name>

SET <column_name = value>

WHERE <condition>;

Ex. UPDATE EMPLOYEE

SET EMP_NAME = 'Emma'

WHERE SALARY = 500000;

- Updating multiple records-

If you want to update multiple columns, you should separate each field assigned with a comma. In
the EMPLOYEE table, update the column EMP_NAME to 'Kevin' and CITY to 'Boston' where EMP_ID
is 5.

Syntax

UPDATE <table_name>

SET <column_name = value1>, <column_name2 = value2>

WHERE <condition>;

Ex. UPDATE EMPLOYEE

SET EMP_NAME = 'Kevin', City = 'Boston'


WHERE EMP_ID = 5;

-Without use of WHERE clause-

If you want to update all row from a table, then you don't need to use the WHERE clause. In the
EMPLOYEE table, update the column EMP_NAME as 'Harry'.

Syntax

UPDATE <table_name>

SET <column_name = value1>;

Ex. UPDATE EMPLOYEE

SET EMP_NAME = 'Harry';

4. SQL DELETE Statement-

The SQL DELETE statement is used to delete rows from a table. Generally, DELETE
statement removes one or more records form a table.

Syntax

DELETE FROM table_name WHERE some_condition;

Deleting Single Record-

Delete the row from the table EMPLOYEE where EMP_NAME = 'Kristen'. This will delete
only the fourth row.

Ex. DELETE FROM EMPLOYEE

WHERE EMP_NAME = 'Kristen';

Deleting Multiple Record-

Delete the row from the EMPLOYEE table where AGE is 30. This will delete two rows(first and third
row).

Ex. DELETE FROM EMPLOYEE WHERE AGE= 30;

Delete all of the records-

Delete all the row from the EMPLOYEE table. After this, no records left to display. The
EMPLOYEE table will become empty.

Syntax

1. DELETE * FROM table_name;


or
2. DELETE FROM table_name;

Ex. DELETE FROM EMPLOYEE;

Note: Difference between DELETE and DROP SQL

DELETE is a Data Manipulation Language command, DML command and is used to


remove tuples/records from a relation/table. Whereas DROP is a Data Definition
Language, DDL command and is used to remove named elements of schema like
relations/table, constraints or entire schema.
Following are the important differences between DELETE and DROP.

Sr. No. Key DELETE DROP

Purpose DELETE Command, removes some DROP Command, removes named


1 or all tuples/records from a elements of schema like relations/table,
relation/table constraints or entire schema.

2 Language DELETE is DML. DROP is DDL.

Clause Where clause is used to add No where clause is available.


3
filtering.

Rollback Delete command can be rollbacked Drop command can't be rollbacked as it


4
as it works on data buffer. works directly on data.

Memory Table memory space is not free if Drop command frees the memory space.
5 Space all records are deleted using Delete
Command.

Problem DELETE command may face DROP Command may cause memory
6
shortage of memory. fragmentation.

Interaction SQL directly interacts with database PL/SQL does not directly interacts with
6
server. database server.

7 Orientation SQL is data oriented language. PL/SQL is application oriented language.

Objective SQL is used to write queries, create PL/SQL is used to write program blocks,
8 and execute DDL and DML functions, procedures, triggers and
statments. packages.

Assignment-

Q1: Insert a single record into emp table.

Q2: Insert more than a record into emp table using a single insert command.
Q3: Update the emp table to set the salary of all employees to Rs15000/- who are living in sikar.

Q4: Create a pseudo table emp1 with the same structure as the table emp .

Ans: SQL> create table emp1 as select * from emp;

Q5: select name, salary from the emp table.

Q6: Delete only those who are working as lecturer.

Q7: List the records in the emp table orderby salary in ascending order.

Q8: List the records in the emp table orderby salary in descending order.

Q9: Display only those employees whose salary is 10000.

Q10: Display name from the table emp avoiding the duplicated values.

Solution:

1. Use SELECT FROM <tablename>.

2.Select should include distinct clause for the name.

Ans: SQL> select distinct name from emp;

You might also like