sql
sql
1)Create command
eid varchar(30),
ename varchar(30),
depid number(30),
salary number(30),
job varchar(30));
2)Student:
create table student
sid varchar(30),
class number(30),
marks number(30),
percentage varchar(30));
3)Patient:
pid varchar(30),
emailed varchar(30));
4)Product
Create Table product
pid varchar(30),
price varchar(30),
emailed varchar(30));
D)Mobile
SNo number(30),
IMEINo varchar(30),
price varchar(30),
DOM date(30));
2)Insert
3)Select
Employee
Product
Student
Patient
4)Rename
5)Alter :
It is used to change modify removing the column heading
Queries :
sno varchar(30),
name number(30),
course number(30),
marks number(30),
percentage varchar(30));
Queries
SNO number(30),
pid varchar(30),
DOM date(30),
price number(30));
Commit;
Queries
4)To change the marks 423 into 740 where sid is 108
A)commit;
Rollback;
Desc emp;
STRUCTURED QUERY LANGUAGE
Sub languages are 5 types they are
OPERATORS
1)Arithmetic operators
2)Relational operators
3) Logical operators
4) String operators
5) Set operators
6) Special operators
1)Arithmetic operators
2)Relational operators
1)>
2)<
Select * from emp where salary>5000;
3)=
4)<>
5)>=
6)<=
Queries:
3)List all the student values where the marks more than 500
5)List all the student values where the name exactly Raju
6)List all the student values where the marks excluding 450
A)select * from student where marks<>450;
3)Logical operators:
and:
or:
not:
1. Display all the emp values where eid is 101 and salary is 9000
2. Display all the emp values where eid is 105 or name is ‘Raju’
3. Display all the emp values in dep is 20 & earnings more than 200
A) Select * from emp where depid=20 and salary>200,
4)Sting operators:
Queries
1.Display all the student values where the sname starts with s
2 Display all the student values where the sname having R as 3rd charecter
3..Display all the emp values who are not earning 2600 and their name starts with s
4)Display all the emp values whose name starts with a and last but two charecters
Select * from emp ename like ‘%a—‘
5)Special operators
The special operators are like in between
Queries:
3.List all the emp values whose salary in the range of 2000 & 5000 and their name starts with s.
Select * from emp where salary in (2000 and 5000) and ename like ‘s%’;
List all the emp valies in dep 10,20 whose salary is not in range 1000 to 2000
Select * from emp where dep in (10,20) and salary not in between (1000,2000);
Display all the employees in dep20 & earning more than 2000 and salary in range 6000,8000
Select * from emp wher dep id=20 and salary>2000 and salary and salary between (6000,8000);
6)Set operators
IV)Classes
1)order by
2)group by
3)having
1)Order by:
Asecending
Descending
Queries
3)Display job wise total salary for the employees working in dep 10,20
4)Display class wise max of marks from and Theri name starts with s.
Select class, max(marks) from student group by class and sname starts with s%;
V)Functions:
1)Group functions
2)Trignometry functions
3)Mathematical functions
4)String
i)Group functions:
ii)Trignometric functions:
3)Mathematiccal functions:
4)String functions
i)Upper()
ii)Lower()
iii)Length()
iv)LTrim()
v)RTrim()
Dual: is a repository it provides all the calculation values auch as trigonometry values ,mathematical
values,Date function values
Query
List all the manager in dep 20,30 & earnings more than 25000
Select * from emp where depid in (20,30) and job=’manager’ and salary>25000;
Or
Select * from emp where depid=20 and job=’manager’ and salary>25000 or depid=30 and
job=’manager’ and salary>25000 ;
8)Constrains:is a condition a business rule which can be applied for database table
1)Domain integrity
2)Entity integrity
3)Referential integrity
i)Not null: it shouldn’t accept zero values & blank spaces but it accept duplicate values.
eid varchar(30),
depid number(30),
salary number(30),
(
eid varchar(30),
depid number(30),
i)Unique:It shouldn’t accept zero values ,blank spaces duplication valies presence at one
valuepresence at only one tiome iin the table
(
eid varchar(30) Unique,
depid number(30),
Foreignkey:The one key creates two or more tables .The 1st table is called parent table and the other
remaining tables Are called Child table.
////
It shouldn’t accept zero valies ,blankspaces & duplicate values i.e, one value present only one time in the
table
(
eid varchar(30)
primary key,
depid number(30),
12)Sublanguages