)
Suppose, in the above student relation we want ta add one more column with attribute hobby. It can be done through
the following statement:
ALTER TABLE STUDENT ADD (HOBBY CHAR (6)); (4 :
‘The above declaration adds a column hobby to the relation student which has already been created.
Another example of using ADD clause you can add a new column into the table.
At FER TABLE STUDENT 29)
ADD (AdmnNo number(10,0));
\
3 ) TRUNCATE TABLE Command
If there is no further use of record stored in a table and the structure has to be retained then the records alone can be
deleted.
Syntax:
a sunctor
TRUNCATE TABLE ; > !f
TRUNCATE TABLE STUDENT, -—+% +
}
‘Truncate command will delete all the rows from student table.
DROP TABLE Command
Aable can be simply. deleted using DROP TABLE command. )But, it is required the table should be empty before any
attempt is made to drop it. The format of this command is:
be
DROP TABLE « table_name >
For example, relation student can be dropped with DROP TABLE student; only owner of the table can delete it with the
DROP TABLE command,
Database Management System (OpenOffice dBase) [B271> a
GQ
OL
SELECT Command
SQL allows the user to make queries on the database with the help of SELECT command. A query is a command useq
to extract certai information from the database relations)SELECT command can be used to retrieve a subset OFrowy,,
cGlunins from one or more tables. The general format of a SELECT command is as under: Sy
SELECT [DISTINCT] [ [WHERE] }
Where.
[SELECT is a SQL reserved word.
DISTINCT isa SQL keyword used to eliminate duplicate rows from the query result.
| is the name of column to be projected.
[FROM is a reserved word
—___| isa relational expression
Let us consider the following relation for answering some queries through SELECT command:
Trainee
St-Name Id_no Course ‘Age Marks DOB
[Suresh 102 T™. 4 85
Raj 101 cD 15 90 20-05-81
Mohan 104 ™ 14 91 10-07-79
Neelu 105 ™ 13, 90 05-05-81
Monu 106 BP 16 95 07-08-80
Deepu 107 ™ 16 86 09-11-82
For viewing just two columns i.e., name & age in the above relation you would write the SQL statement:
SELECT NAME, AGE FROM TRAINEE; <5:
‘The above statement will give the following output:
NAME AGE
Suresh 4
Raj 15
Mohan 14
Neelu 1B
Monu 16
Deepu 16
For viewing all the columns of the relation we don’t need to. make list of all the attributes of the relation. Instead asterisk
(“can be substituted for the complete list of column attributes,/The following command will list all the columns °!
relation Trainee - 7
SELECT * FROM TRAINE]
1i we project some column (3) of @ relation using,
duplicate entries in the result, for example:
\e2 Information Technology - 10
nany
LECT Command then there i lity that there are ™
—SELECT Age FROM TRAINEE, (€4
Produces the following output
AGE
4
15
4
1B
16
16
16
‘The duplicate entries can be eliminated using DISTINCT keyword as:
SELECT DISTINCT Age FROM TRAINEE; ( €4
‘The output ofthis query will be:
Age
4
‘fin the place of DISTINCT, we give ALL then the result retains all the duplicate values. Thus, itis just the same as when
we neither specify DISTINCT nor ALL. In this way, we can say ALL is not an argument but just a qualifier. —
Sheer Command
‘The INSERT command is used to append a row or tuple to_a table. The syntax of the command is:
INSERT INTO VALUES (,...) Aysafor
Where,
rel_name is the relation name
val_kis the value ofthe kt
For example, the following command will append a row into relation student:
INSERT INTO Trainee
VALUES (‘Ram, ‘CD, 110, 17, 86,"17/8/90');
UPDATE Command.
‘This SQL statement is used to change column values of a particular row. The row is normally selected using WHERE
clause and the columns within that row are set to new values using the SET keyword./Format of the statement is :
UPDATE
SET f
=
WHERE ;
Where,
\#e_name is the name ofthe relation
__altr_name_kis the name of the kth attribute
~-tiéw_val_k is the new value to be asigned to attribute k
For example, to change marks of Mohan to 85 we would write the statement as:
Datatase Management System (OpenOffice dBase)UPDATE trainee
SET mark
WHERE trim(name) = “Moh
Similarly, to change Mohanis marks to 85 and his course to "M>" the command may be written as
UPDATE Trainee
SET marks = 95, Course = "MP" “) L
WHERE trim (name) = ‘Mohan -
S DELETE Command
This command is used to delete one or more rows which can be selected for deletion using WHERE clause. Individua
attributes of a row cannot be deleted using this statement. The format of the statement is:
DELETE tel name> Cpecho> DELLE FRom