0% found this document useful (0 votes)
6 views

lab2

Uploaded by

maheshgiri9988
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

lab2

Uploaded by

maheshgiri9988
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab 1:

**********
DML command
***********
1> create database
create db database_name.
2) use database
use database_name;
*********************

3) create table
*******************
4)ALTER TABLE:(add column)
**********************
ALTER table student
ADD saddress varchar(25);
****************************8
5) Drop column
*****************
ALTER table student
DROP COLUMN saddress;
************************
5)Insert record into table

LAB 2
**********
INSERT
**********
a) INSERT [into] <table> values (val1, val2, val3.....)
*All column values
insert into student values(1,'chakra', 'B', '[email protected]', '98345')
*Selected column values
b) insert into studenet(sid,name)values('5', 'Rawal')
*without into

*inset<tn> vlues()*
insert student values(5,'Rawal', 'd', '@yahoo',24455)

UPDATE
**********
a) to update specific rows

UPDATE <table name>


SET <colName1>=value1, <col2 name>=value2
WHERE ()

UPDATE student SET sid=5 WHERE contact=98345


****
UPDATE student1
SET sname ='Ramesh', age=25
WHERE sno=2;
**************************************
b)IS NULL
UPDATE student SET section='c' WHERE section IS NULL
c) all row update
UPDATE student SET eaddress='[email protected]'
UPDATE student SET eaddress='[email protected]'

DELETE
**********
a)specific row
delete form <tbl_name> where (condition)
DELETE FROM student WHRE section='b'

DELETE FROM STUDENT WHERE section='b'

IS NULL
******
DELETE FROM student WHERE contact IS NULL
DELETE ALL
**************

DELETE FROM student

DQL or DRL
***********
Data query Language:
*SELECT
-Retrive Data
SELECT *from <table_name>
SELECT <column_names> FROM <table_name> WHERE (condition)
SLECT sid, sname FROM student
****************************

retrieve data
***********
-projection: without condition ***single
-selection : With condition ***single table

-joins : to retrive data from multiple table

a) ANSI Format with on key word join condition


-inner join
-outer join
left/right/full outer
-Natural join
-Cross join
***

LAB 3
*********
Create Table
*Studenet with--->s_id, email, courseId
and
*Course with--->courseId, c_name, c_fee

*same column in both table is courseId


use inner join
--retrieve common column
>select *<columns> from <tb> join <tb> on joining
>select *from student INNER JOIN course
ON student.courseId=couse.courseId
for retrieve same(matching) data
Outer join **matched and unmatched
*left outer join
>select *from student s LEFT OUTER JOIN
course c ON s.courseId=c.courseId
Right outer join
> select *from student s RIGHT OUTER JOIN
course c ON s.courseId=c.courseId
Full outer join
>select *from student s FULL OUTER JOIN
course c ON s.courseId=c.courseId

CROSS Join
>SELECT *from student CROSS JOIN course
*

NATURAL JOIN
*******
-basically not supported sql server
-avoid duplicate tuples//oracle supported

*** equi-join/equi-joins
*********************
identity function /method
Identity (seed, increment) //auto increment value
**in perticular column
seed -> starting value
increment->
one table -> one identiy function
create table student( eid INT IDENTITY, ename varchar(20))
*********************
SHELF JOIN
***
select *from empdetail where salary=11000
select *from empdetail where name ='ram'
Joining data itself
select *from student s, course c where s.courseId=c.courseId and s.name='ram'
LAB 3A
************
Set operation:
**
-Combine select statement
-Union
-union all
-intersect
-except
*****
a) number of column in both select statement.
b) order of the column is same.
c) data type of the colmun must matched.
Create table emp1 and emp2
*************************
Union
select *from emp1
UNION
SELECT *FROM emp2
*no duplicate values.
UNION ALL
***********
select *from emp1
UNION ALL
SELECT *FROM emp2
*duplicate value is also display
Except
********
retrun all values from the left hand side table
which are not found in the right hand table
****
select *from emp1 EXCEPT select *from emp2

Table Relationship
*****************
- Key constraint
* primary key
* foreign key
*****
a) one table contain primary key and
another table contains foreign key
b) a common column in both tables
c) common column data type must be same in both talbes
****
1.Create table department.
2. create table employee

Create Deprtment table


with dep_no as primary key, dep_name, location)

create table department( dep_no int primary key,


d_name varchar(20), d_location varchar(20);

create a table employee


***********************************************************************
create table employee(e_id int, e_name varchar(20),
salary money, d_no int foreign key refrences department(d_no))
**select
select *from department
select *from employee
-select *from <tab1>,<tab2>
SELECT <...>
FROM<tab1>, <tab2>
WHERE .......

Cartesian product
**********************

You might also like