lab2
lab2
**********
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
DELETE
**********
a)specific row
delete form <tbl_name> where (condition)
DELETE FROM student WHRE section='b'
IS NULL
******
DELETE FROM student WHERE contact IS NULL
DELETE ALL
**************
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
LAB 3
*********
Create Table
*Studenet with--->s_id, email, courseId
and
*Course with--->courseId, c_name, c_fee
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
Cartesian product
**********************