38
INSERT, UPDATE and DELETE, to allow the addition of rows, the changing of values
in rows, and the deletion of rows, respectively, to or from a table.
INSERT: - Insert operation that causes rows to be added to a table,
Syntax: - INSERT into table name (column1, column2----------n)
VALUES (value1, value2----------value ‘n’);
OR
INSERT into table name values (&column1, &column2, ---------&column n);
Ex: -sql>Insert into Employee (Empno, Empname, Address, Phone no, ----)
VALUES (102, ‘NEELIMA’, ‘UPPAL’, ‘HYD’, 23456, ----);
UPDATE: - Operation that changes column values in rows. UPDATE Operations always
apply to all the rows that satisfy the WHERE clause in the UPDATE statement. TO
UUPDATE
*All the rows from a table
Or
*A select set of rows from a table.
UPDATING OF ALL ROWS:
Syntax: - update table name SET columnname1= Expression, column
name2=Expression2;
Ex:-Change Dept= sales where dept= sales1 of a employee table.
Sql>Update Employee SET DEPT= ‘sales’ where dept =’sales1’;
Built – in- Functions:
SQL provides fire statistical functions that examine a set if rows in a relation and
produce a single value. Functions are SUM, AVG, COUNT, MAX, and MIN.
Query:-What is the highest and lowest salary in employee table?
Sql> SELECT MAX (SALARY), MIN (SALARY) FROM EMP1;
The MAX and MIN functions operate on a single column in a relation. They
select the largest (or) the smallest value, respectively, to be found in that column.
COUNT (*):-Returns the number of rows in the table, including duplicates and those
with nulls.
Ex:- sql>SELECT COUNT (*) “TOTAL”FROM EMP;
*Emp1 is table name
SUM:-Returns sum of values of ‘n’
Ex:-sql>SELECT SUM (SALARY) ‘TOTAL AMOUNT’FROM Emp1;
OUTPUT:-TOTAL AMOUNT
What is the average salary paying for employees?
AVG:-sql>SELECT AVG (SALARY) “AVERAGE “FROM EMP1;
Returns average value of ‘n’ ignoring null values.
Multiple- Table Queries:-Some times data needed to solve the query from two tables.
This is accomplished through the relational calculus i.e., “Join”.
Ex:-1 Worker :-( worker ID, Name, Howdy-Rate, Skill type, SOPV-ID)
2 ASSIGNMENT (Worker ID, BLPG-ID, Start Data, NUM-Days)
In above example, there are two tables i.e. WORKER, ASSIGNMENT.