0% found this document useful (0 votes)
5 views13 pages

Lab 06 - SQL (DML)-01

Data Manipulation Language

Uploaded by

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

Lab 06 - SQL (DML)-01

Data Manipulation Language

Uploaded by

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

SQL (DML)

Data Manipulating Language (DML)


• Data Manipulation Language (DML)
statements are used for managing data within
schema objects.

• Some examples:
– INSERT - insert data into a table.
– SELECT - retrieve data from the database.
– UPDATE - updates existing data within a table.
– DELETE - deletes all records from a table, the
space for the records remain.
Insert into
• The SQL INSERT INTO Statement is used to
add new rows of data to a table in the
database.
• There are two basic syntaxes of INSERT INTO
statement as follows:
– INSERT INTO TABLE_NAME (column1, column2,
column3,...columnN)] VALUES (value1, value2,
value3,...valueN);

– INSERT INTO TABLE_NAME VALUES


(value1,value2,value3,...valueN);
Insert Into Example
– INSERT INTO CUSTOMERS
(ID,NAME,AGE,ADDRESS,SALARY)VALUES (1,
'Ramesh', 32, 'Ahmed abad', 2000.00 );

– INSERT INTO CUSTOMERS VALUES (7, 'Muffy', 24,


'Indore', 10000.00 );
Select
• SQL SELECT statement is used to fetch the
data from a database table which returns data
in the form of result table. These result tables
are called result-sets.

• The basic syntax of SELECT statement is as


follows:
– SELECT column1, column2, columnN FROM
table_name;
– SELECT * FROM table_name;
Basic Select Examples
– SELECT ID, NAME, SALARY FROM CUSTOMERS;
– SELECT * FROM CUSTOMERS;
Where / and / or - Clause
• Where clause:
– The SQL WHERE clause is used to specify a
condition while fetching the data from single table
or joining with multiple tables.

• AND | OR clause
– YOU CAN JOIN SEVERAL CONDITIONS USING
(AND, OR)
Where clause:

• WHERE salary>1300
• WHERE name=’Ahmad’;
• WHERE city IN (‘Jenin’, ‘Ram Allah’);
• WHERE salary BETWEEN 1500 and 3000;
• WHERE OrderDate BETWEEN #07/04/1996# AND
#07/09/1996#;
• WHERE salary NOT BETWEEN 1500 and 3000;
LIKE clause

• The SQL LIKE clause is used to compare a value to


similar values using wildcard operators. There are two
wildcards used in conjunction with the LIKE operator:
– The percent sign (%) ; the percent sign represents zero, one,
or multiple characters.

– The underscore (_); the underscore represents a single


number or character.
• The symbols can be used in combinations ( _ _ _), But if ;for
example; city name contains ( _ ) like Jenin_City then we can use
( \ ) to treats ( _ ) as a character.
– Examples
• WHERE city_name LIKE ‘%in\_City’;
• WHERE name like ‘Mr. %’;
• WHERE product like ‘% table%’;
ORDER BY clause
– SELECT column-list FROM table_name [WHERE
condition] [ORDER BY column1, column2, ..
columnN] [ASC | DESC];

– SELECT * FROM CUSTOMERS ORDER BY NAME, SALARY;

– SELECT * FROM CUSTOMERS ORDER BY NAME DESC;


DISTINCT
• The SELECT DISTINCT statement is used to
return only distinct (different) values.

• Inside a table, a column often contains many


duplicate values; and sometimes you only
want to list the different (distinct) values.

– SELECT DISTINCT column1, column2, ...


FROM table_name;
Insert / select
• You can populate data into a table through
select statement over another table provided
another table has a set of fields, which are
required to populate first table. Here is the
syntax:

– INSERT INTO first_table_name [(column1,


column2, ... columnN)] SELECT column1,
column2, ...columnN FROM second_table_name
[WHERE condition];
Schema Example / HR Schema Oracle

You might also like