Page 162 - Informatics_Practices_Fliipbook_Class12
P. 162
Next, suppose we want to assign a manager (ID = '10002')to the department having Dept_No 1. The following
UPDATE statement finds a tuple in the DEPARTMENT table having Dept_No 1 and sets the value of its Mgr_Id
attribute to 10002.
UPDATE DEPARTMENT
SET Mgr_Id = '10002'
WHERE Dept_No = 1;
On execution of the above SQL statement, DEPARTMENT table appears as shown in Table 4.5
Dept_No Dept_Name Location Mgr_Id
1 Accounts Noida 10002
2 Administration Delhi 10005
3 Home Goods Mumbai 10003
4 Automobile Jamshedpur 10007
5 Textile Mumbai 10004
Table 4.5: Result of UPDATE statement on DEPARTMENT table
4.4.9 SELECT statement
SELECT statement is used to retrieve information from database tables. Such statements are also known as SQL
queries. Syntax of a simple SELECT statement is given below:
SELECT attribute_list
FROM table_name;
attribute_list is a comma-separated list of names of the attributes whose value is to be retrieved. For example,
the following SQL statement retrieves department number, name and location for all the departments.
SELECT Dept_No, Dept_Name, Location
FROM DEPARTMENT;
In the above statement, the first line is the SELECT clause that comprises the keyword SELECT and a list of attributes
Dept_No, Dept_Name, Location. The second line is called FROM clause. Execution of the above statement
will produce the output shown in Table 4.6:
Dept_No Dept_Name Location
1 Accounts Noida
2 Administration Delhi
3 Home Goods Mumbai
4 Automobile Jamshedpur
5 Textile Mumbai
Table 4.6: Dept_No, Dept_Name, Location for the DEPARTMENT table
Similarly, the following SQL statement yields information about all employees working in the company from the
EMPLOYEE table:
SELECT ID, FName, LName, Gender, Address, City, Pin_Code, DOB, Salary, Dept_No
FROM EMPLOYEE;
When we need to display all attributes in a table, we use the wildcard character * (asterisk) as a placeholder for all the
attributes of the table specified in the FROM clause, as shown below:
SELECT *
FROM EMPLOYEE;
148 Touchpad Informatics Practices-XII

