Structured Quey Language2-Database Systems
Structured Quey Language2-Database Systems
Structured Quey Language2-Database Systems
Database systems
M.Y Abdur Rahman
Group by
Statements Order by
View
Join
Project
Questions project_no project_name city
(pk)
Shipment
shipment_no quantity part_no project_no
Question 02: Find the minimum quantity for each project and
Answer display in descending order of the project number from shipment
table.
Question 04: Find the average quantity supplied for each project
Answer and display the result in descending order of average quantity.
For this query quantity more than 100 will not be valid.
Department
Joins Dept_no Dept_name
(pk)
create table department(dept_no varchar(20) not null primary
key,dept_name varchar(20));
insert into department(dept_no,dept_name)
values('d01','finance'),('d02','HR'),('d03','IT'),('d04','admin');
create table employee(emp_id varchar(20) not null primary
key,emp_name varchar(20),emp_salary int,dept_no
Query varchar(20),foreign key(dept_no) references
department(dept_no));
insert into employee(emp_id,emp_name,emp_salary,dept_no)
values('e01','amal',10000,'d02'),('e02','Kamal',15000,'d02'),
('e03','Saman',12000,'d01'),('e04','Ajith',14000,'d02');
Question 05: Write a query to list employee name and salary from
the employee table and department number and name from
department table .
select e.emp_name,e.emp_salary,d.dept_no,d.dept_name from
employee e, department d where e.dept_no=d.dept_no;
Answer
IT is like a virtual table that contain data from one or multiple
table.
We can also control the user security for accessing data from the
database table.
Present only the data which user require access
Create view <view name>(attribute)
view AS
Query
Question 05:create a view called vEmployee having name and city.
Security & access control REVOKE <Priviledge list> ON <object> FROM <subject>
commands in SQL- revoke
Eg: revoke insert on supplier from Saman
CREATE FUNCTION function_name(@parameter (data type))
RETURNS return_datatype
AS
BEGIN
RETURNS return _datatype
SQL functions END;
https://www.youtube.com/watch?v=MlaAX59l2b4
CREATE PROCEDURE procedure_name(parameter data type)
AS
BEGIN
END;
SQL stored To execute stored procedure:
Execute procedure_name;
procedure Exec procedure_name
Just procedure_name;
https://www.youtube.com/watch?v=7DoFxbBuqx0
CREATE TRIGGERS trigger_name(parameter data type)
ON
FOR
AS
SQL trigger BEGIN
END;
https://www.youtube.com/watch?v=KLJ29y3qqyk
Stored procedure Trigger
We can execute a stored A trigger can only be executed
procedure whenever we want whenever or event(insert,
using the exec command. delete and update) is fired ion
Stored We can call a stored
the table.
Transaction (a)T1
(a)T2
read_item(x)
read_item(x)
x:=x-N;
x:=x+M;
write_item (x)
write_item (x)
read_item(y)
y:=y+n;
write_item(y);
Transfer Rs 5000 from account A to B.
T1
read_item(A)
Exercise A:=A-5000;
write_item(A)
read_item(B)
B:=B+5000;
write_item(B);
END