DML (Data Manipulation Language)

DML is a sub-language of SQL. It is used to manipulate the data stored in a table.

DML provides the following statements for data manipulation:

  • INSERT
  • UPDATE
  • DELETE

INSERT Statement

INSERT statement is used to insert a new record into a table.

Syntax:
INSERT INTO <TABLE_NAME>[(COLUMN1, COLUMN2, ... N)]
VALUES(VALUE1, VALUE2 ... N);
Example

Consider a table 'EMP' having columns named EMPNO, NAME, SAL and JOB. We can used the below INSERT statement to insert a new record to it.

INSERT INTO EMP
VALUES('1','ALAN',5000,'CEO');

INSERT statement can be used without the column names, when data is inserted into all the columns of the table. The values to be inserted in each column should come in the same sequence in the insert statement as are the columns in the table.

The below example uses column name, since the columns are not in the same sequence as in the table. Also all columns are not used. The column left out will be filled with NULL.

INSERT INTO EMP(NAME, JOB, SAL)
VALUES('NICK','MGR',3000);

The below example uses NULL keyword to insert null value into the JOB column.


UPDATE Statement

Update statement is used to update an existing record in a table.

Syntax:
UPDATE <TABLE_NAME>
SET <COLUMN_NAME>=VALUE[, <COLUMN_NAME> VALUE ... N]
[WHERE <CONDITION>];

If the where clause of omitted, the statement will update all the values in the particular column.

Example:
UPDATE EMP
SET SAL=15000
WHERE EMPNO=1

UPDATE EMP
SET SAL=12000, JOB='VP'
WHERE EMPNO=NULL

Note: IS NULL is used for assignment and =NULL is used to recognize.

Example:
UPDATE EMP
SET JOB=NULL
WHERE EMPNO IS NULL;

DELETE Statement

Delete Statement is used to delete records from a table.

Syntax:
DELETE FROM <TABLE_NAME>
[WHERE <CONDITION>];
Examples:
DELETE FROM EMP
WHERE EMPNO=1;

Below statement will delete all records from the table.

DELETE FROM EMP;
POPULAR ARTICLES

Creating Conditional Beans in Spring

The concept of condition beans enables Spring to restrict the creation of any bean depending on the evaluation of a condition. These beans get created only when a preset condition is evaluated as true

View Article

Accepting Request Param and Path Variable in Spring Controller

Spring MVC provides various ways through which a client browser can pass data to the Controller. In this article we will discuss about accepting Request Parameters and Path Variables in Spring Contr..

View Article

Generate Namespace & Schema Information using JAXB

Most xml documents used in enterprise applications makes use of namespace to avoid element name conflicts. This article talks about generating these namespace and schema information when marshaling...

View Article

Switching Database Profile using Spring Profiles

We are most likely to have separate db configuration for different environment like development and production environment. Spring profiles provide a convenient way to switch db profiles at runtime.

View Article

SQL and its Sub-Languages

SQL (Structured Query Language) is a language understood by most modern databases. It is an ANSI (American National Standard Institute) standard language which is used to manipulate databases.

View Article

Introducing JUnit Rule

Junit Rules allows developers to add additional functionalities that can applied to all test methods in a test class. It is similar to the concept of custom test runners but with reduced restrictions.

View Article

Addressing Ambiguity in Spring Autowiring

Spring autowiring is powerful concept, but we should be very cautious while using it. We may end up in creating ambiguity while autowiring beans, which will cause autowiring to fail.

View Article

Creating and Using Synonym in Oracle Database

Synonyms are database objects used to provide duplicate names to existing objects in the database. It is just an alternate name used to hide the original name of the object.

View Article

Creating and Using Sequence in Oracle Database

A sequence is used to auto-generate numbers in ascending or descending order which can serve as a primary key or a part of it (in case of composite key).

View Article

Creating and Manipulating Constraints in Oracle Database

Constraints are used to impose certain rules on columns to avoid invalid data entry into the table. If any of the constraint is violated the operation fails.

View Article

Integrating Log4J with Perf4J for Performance Logging

Perf4j is an open source logging framework used primarily for monitoring performance statistics in java applications. Log4j has the ability to integrate with perf4j to capture performance data.

View Article

Tagging in GIT

Tagging allows us to mark a specific point in the commit history or snapshot. A tag is typically used to mark a project release. This article shows how to create tags in Git.

View Article