Professional Documents
Culture Documents
1 Sachin 23 2
2 Virat 19 1
3 Rohit 20 2
Table 2:City table
P
F
cid city
1 delhi
2 Mumbai
F
P
empid empname depti city mgrid salary doj
d
Table Emp
Creating table dept
Create table emp
( emp_no smallint primary key,
F_name varchar(15),
L_name varchar(15),
J_code smallint ,
H_date date,
Sal int );
Insert into Table
Insert into EMP
Values( values in the order of colmns given at the time
of creation.);
eg.
Insert into emp
Values(1, ’amit’, ’shah’ , 2 , ’1992-11-21’ ,84000);
Insert
Insert into emp
Values(1,’samir’,’desai’,1,’2004-1-12’,12000);
Inserting more values
Insert into emp
Values(2,’sandip’,’more’,2,’2006-9-21’,10000),
(3,’sarika’,’nene’,1,’2008-12-1’,8500),
(4,’sapana’,’lele’,2,’2007-10-11’,9000);
Insert into Table
If data is not provided for all columns then column
names for which the data is provided is to be mention
in the parenthesis
E.g.
Insert into emp
(emp_no,L_name,J_code,sal)
Values(5,’Mehta’,2,30000);
Update & set
Existing records can be modify
eg.
Update student
Set name=‘sunil’
Where r_no=1;
Change surname to ‘patel’ and salary to 45000 for
emp_no 10.
Update emp
SET l_name=‘patel’,sal=45000
Where emp_no=10;
Update & Set
The update and set statements are used to modify the
data in the rows of table.
E.g. to change the age of employee id 4(hiral) to 29 in
pay table the command is
Update pay
Set age=29
Where empid=4;
Syntax
UPDATE table_name
SET column 1=value 1,column 2=value 2………
WHERE condition;
HW
Give values to the city and dob columns for empid=4
which are at present NULL
To increase age by 1 and the salary by 5000 for rows
with city Mumbai
Creating a table using another Table
CREATE TABLE table_name
SELECT column 1,column 2….
FROM table_name;
Alter table
To Add column
Alter table table_name
Add Column_name datatype;
To add multiple colums
Alter table table_name
Add (col_1 datatype