0% found this document useful (0 votes)
46 views9 pages

Dbms Experi

This document describes executing SQL commands to manipulate data. It discusses: 1. The Data Manipulation Language (DML) commands SELECT, UPDATE, DELETE, and INSERT INTO for retrieving, modifying, deleting and inserting database data. 2. Examples of using INSERT to add rows, SELECT to retrieve rows, UPDATE to modify rows, and DELETE to remove rows. 3. Additional SELECT examples including DISTINCT, WHERE clauses, ordering results, UNION, INTERSECTION, and aggregate functions. 4. Nested queries using a sub-query to filter results. The aim was to execute DML commands on database tables to manipulate the data. Examples demonstrated the syntax and use of key DML statements.

Uploaded by

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

Dbms Experi

This document describes executing SQL commands to manipulate data. It discusses: 1. The Data Manipulation Language (DML) commands SELECT, UPDATE, DELETE, and INSERT INTO for retrieving, modifying, deleting and inserting database data. 2. Examples of using INSERT to add rows, SELECT to retrieve rows, UPDATE to modify rows, and DELETE to remove rows. 3. Additional SELECT examples including DISTINCT, WHERE clauses, ordering results, UNION, INTERSECTION, and aggregate functions. 4. Nested queries using a sub-query to filter results. The aim was to execute DML commands on database tables to manipulate the data. Examples demonstrated the syntax and use of key DML statements.

Uploaded by

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

Experiment No .

03
AIM: To execute the DATA DEFINITION LANGUAGE (DDL) commands.

Data Definition Language (DDL) is a computer language for defining data structures. The term
was first introduced in relation to the Codasyl database model, where the schema of the database
was written in a Data Definition Language describing the records, fields, and "sets" making up
the user Data Model.

The DDL part of SQL permits database tables to be created or deleted. It also defines indexes
(keys), specifies links between tables, and imposes constraints between tables. The most
important DDL statements in SQL are:

CREATE DATABASE - creates a new database

ALTER DATABASE - modifies a database

CREATE TABLE - creates a new table

ALTER TABLE - modifies a table

DROP TABLE - deletes a table

CREATE INDEX - creates an index (search key)

DROP INDEX - deletes an index

CREATING A TABLE

Syntax:
Create table <table name> (column 1 datatype 1,., column n datatype n);
Explanation:
Create command is used to create a table in the database.
Example:
SQL> create table student (VT number, name varchar (10));
OUTPUT:
Table created.

DESC COMMAND
Syntax:
desc <table name>;
Explanation:
This command is used to view the structure of the table.
Example:
SQL> desc student;
OUTPUT:
NAME NULL? TYPE
VT NUMBER
NAME VARCHAR (10)

ALTERING A TABLE

Explanation:
The structure of the table can be changed using this command like add new column, change the
width of a datatype, change the datatype of a column.

1. MODIFY
SYNTAX:
alter table <table name> modify (column datatype, );
EXAMPLE:
SQL> alter table student modify (name varchar (20));
OUTPUT:
Table altered.

2. ADD / DROP
SYNTAX:
alter table <table name> add/drop (column datatype, );
EXAMPLE:
SQL> alter table student add (dept varchar (20));
SQL> alter table student drop (addr);
OUTPUT:
Table altered.

TRUNCATING A TABLE

truncate table <table name>;


EXPLANATION:
This command is used to delete all records stored in a table, but the structure of the table is
retained.

EXAMPLE:
SQL> truncate table student;
OUTPUT:
Table truncated.

DROPPING A TABLE
SYNTAX:
drop table <table name>;

EXPLANATION:
This command is used to remove a table from the database.
EXAMPLE:
SQL> drop table student;
OUTPUT:
Table dropped.
RESULT:
Thus, the data definition language commands were executed and their outputs were verified.
Experiment No .04
AIM: To execute the DATA MANIPULATION LANGUAGE (DML) commands.

The Data Manipulation Language (DML) is used to retrieve, insert and modify database
information. These commands will be used by all database users during the routine operation of
the database. Let's take a brief look at the basic DML commands:

The query and update commands form the DML part of SQL:

SELECT - extracts data from a database

UPDATE - updates data in a database

DELETE - deletes data from a database

INSERT INTO - inserts new data into a database

INSERT COMMANDS

INSERT A ROW WITH VALUES FOR COLUMNS IN A TABLE.

SYNTAX:
insert into <table name> values (value1, value2,, value n);
EXPLANATION:
This insert command is used to add rows to a table in the database.

EXAMPLE:
SQL> insert into student values (4169, rameeze);
OUTPUT:
1 row created.

INSERT A LARGE NUMBER OF ROWS.

SYNTAX:
insert into <table name> values (&value1, &value2,, &value n);
EXPLANATION:
This insert command is used to add multiple rows to a table in the database.
EXAMPLE:
SQL> insert into student values (&vt, &name);
OUTPUT:
Enter value for vt: 4169
Enter value for name: rameeze
Old 1: insert into student values (&vt, &name)
New 1: insert into student values (4169, rameeze)
1 row created.

SELECT COMMANDS

SELECT ALL ROWS FROM A TABLE.

SYNTAX:
select * from <table name>;
EXPLANATION:
This select command is used to retrieve all the values stored in the table.

EXAMPLE:
SQL> select * from student;
OUTPUT: VT NAME

SELECT DISTINCT ROWS FROM A TABLE.

SYNTAX:
select <field name> from <table name>;
EXPLANATION:
This select command is used to retrieve the particular field values stored in the table.

EXAMPLE:
SQL> select name from student;
OUTPUT: NAME RAMEEZE

SELECT USING WHERE COMMAND.

SYNTAX:
select <field name> from <table name> where <search condition>;
EXPLANATION:
This select command is used to retrieve the particular field values, stored in the table, which
satisfy a required condition.

EXAMPLE:
SQL> select name from student where vt=4169;
OUTPUT: NAME RAMEEZE

UPDATE COMMAND
SYNTAX:
update <table name> set column1=expression, column 2=expression, ,
column n=expression where <search condition>;
EXPLANATION:
This command is used to update (changing values in) one or two columns of a row in a table.
Specific rows can be updated based on some condition.

EXAMPLE:
SQL> update student set name=md rameeze where vt =4169;
OUTPUT: 1 row updated.
SQL> select * from student;
VT NAME 4169 MD RAMEEZE

DELETE COMMAND

SYNTAX:
delete from <table name> where <search condition>;
EXPLANATION:
This command is used to delete a row from a table.

EXAMPLE:
SQL> delete from student where vt =4169;
OUTPUT: 1 row deleted.
Experiment No .05
AIM: Execution of SQL Queries, Aggregate Functions and Nested Queries.

1. SELECT
Example: select name from cust;
Output: NAME hayes jones blake

2. WHERE
Example: select city from cust where name= hayes;
Output: CITY Harrison

3. FROM
Example: select name, city from cust;
Output:
NAME CITY
hayes harrison
jones redwood
blake downtown

4. RENAME
Example: select borrower.loan_no as loan_id from borrower;
Output: LOAN_ID

5. STRING OPERATIONS
(a) % .
Example: select name from cust where city like har%;
Output:
NAME
hayes
smith
(b) _ .

Example: select city from cust where name like _ _ _ _ _;


Output: CITY
harrison
redwood
downtown

6. ORDERING OF TUPLES
Example: select * from loan order by amount asc;
Output: LOAN NO BRANCH AMOUNT
7. UNION
Example: (select name from depositor) union (select name from borrower);
Output:
NAME
adams
britto
hayes
jones
smith

8. INTERSECTION

Example: (select name from depositor) intersect (select name from borrower);
Output: NAME
hayes
jones

9. AGGREGATE FUNCTIONS
(a) AVERAGE.
Example: select avg (balance) from account;
Output: AVG (BALANCE)
487.5
(b) MINIMUM.
Example: select min (balance) from account;
Output: MIN (BALANCE)
350
(c) MAXIMUM.
Example: select max (balance) from account;
Output: MAX (BALANCE)
700
(d) TOTAL.
Example: select total (balance) from account;
Output: SUM (BALANCE)
1950
(e) COUNT.
Example: select count (balance) from account;
Output: COUNT (BALANCE)
4

10. NESTED QUERIES

Example: select name from depositor where depositor.name in (select name from
cust);
Output: NAME
hayes
jones
RESULT:
Thus, the queries in SQL were executed and the outputs were verified.

You might also like