You are on page 1of 4

EXPERIMENT NO-5

AIM – To modify the contents and the structure of the tables.

DML or Data Manipulation Language is a language that enables users to access or


manipulate data as organized by the appropriate data model. After the database scheme
specified and the database has been created, the data can be manipulated using a set of
procedures which are expressed by Data Manipulation Language. DML or Data
Manipulation Language division of SQL, is dedicated to manipulating data in one way
or another. For example, the UPDATE command is used to change or modify the
contents of the table.

THE UPDATE COMMAND The UPDATE command is used to modify attribute


values of one or more selected rows. Like in DELETE command, the WHERE clause in
the UPDATE command selects the rows to be modified from a single relation.an
additional SET clause specifies the attributes to be modified and their new values. The
syntax of the UPDATE command is

UPDATE <tablename>
SET [ <columnname1> = <value expression>.
<columnname2> = <value expression>
…….
]
[WHERE <condition>]

The columns whose values have to be updated and the expressions to derive these values
are included in the SET clause. The rows to be updated are those that meet the
condition(s) in the WHERE clause.

For example to update the basic salary of the employee,we could use the following
statement

Update EMPLOYEE
SET basic=3000
WHERE e_code=’101’;

This command will change the salary of the employee whose employee code is 101 with
3000.
The output for the UPDATE command is shown in the tables related to project

update STUREPT
SET intmarks=74
where adno=1002;
update STUDATA
SET city='bhilai',religion='christian'
where adno=1002;

Data Definition Language or DDL commands are used to define a database, modify its
structure after it has been created and destroy it after it is no longer needed. The result of
compilation of DDL statements is a set of tables which are stored in a special file called
DATA DICTIONARY. One of the DDL command is ALTER TABLE, which is used
to change the definations of existing languages.

ALTER TABLE COMMAND It is possible to modify the structure of a table even if


rows have already been inserted into this table. This is done by the ALTER TABLE
command. It is used to change the definitions of existing tables. Usually a column can be
added using the ALTER TABLE command. The syntax of the ALTER TABLE
command is
ALTER TABLE <tablename>
MODIFY<columnname>
<new details for the column>;

OR

ALTER TABLE<tablename>
ADD <columnname> <datatype> <size>;

For example to alter the size of the employee name field, we could use the following
statement

ALTER TABLE EMPLOYEE


MODIFY ename
char(10);

to add the age field to the table EMPLOYEE, we could use the following statement

ALTER TABLE EMPLOYEE


ADD(AGE INT);

The output for the UPDATE command is shown in the tables related to project

alter table STUREPT


add(schdtest number(4));

alter table STUREPT


drop column SCHDTEST;
alter table STUDATA
modify city
char(18);

You might also like