0% found this document useful (0 votes)
12 views9 pages

dbms1 3

Useful for practical

Uploaded by

Jenifer M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

dbms1 3

Useful for practical

Uploaded by

Jenifer M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

REGNO:311521205305

PROGRAM:

create table Team2(tname number, tmembers varchar(10), age number ,dob number);
alter table Team2 add (dept varchar(20));
rename Team2 to Sport1;
drop table Sport1;
desc Sport1;

OUTPUT:

RESULT:
REGNO:311521205305

PROGRAM:

create table Play (tname varchar(20), tmembers varchar(20), age number ,dob number);
insert into Play values('India','Mary Kom',40,24-11-1982);
insert into Play values('India','Sania Mirza',36,15-11-1986);
insert into Play values('India','Virat Kholi',34,05-11-1988);
select tname,tmembers,age from Play where age between 30 and 37;
select tname,tmembers,age from Play where age not between 30 and 37;
select tname,tmembers,age from Play where age in 34;
select tname,tmembers,age from Play where age not in 34;
select * from Play;
select * from Play order by AGE asc;

OUTPUT:

RESULT:
REGNO:311521205305

PROGRAM:

CREATE TABLE employees (


id INT PRIMARY KEY,
name VARCHAR(50),
age INT,
salary DECIMAL(10,2)
);

INSERT INTO employees (id, name, age, salary)


VALUES
(1, 'John', 25, 50000.00),
(2, 'Sarah', 30, 60000.00),
(3, 'Mike', 40, 70000.00),
(4, 'Lisa', 22, 45000.00),
(5, 'David', 35, 80000.00);

SELECT name, salary


FROM employees
WHERE age > 25;
SELECT AVG(salary)
FROM employees
WHERE age > 25;
SELECT COUNT(name)
FROM employees
WHERE age > 25;

OUTPUT:
REGNO:311521205305

RESULT:
REGNO:311521205305

PROGRAM:

CREATE TABLE employees (


id INT PRIMARY KEY,
name VARCHAR(50),
age INT,
salary DECIMAL(10,2)
);
INSERT INTO employees (id, name, age, salary)
VALUES
(1,'Alex',25,1000000),
(2,'Rhys',35,100000),
(3,'Josh',28,200000),
(4,'Dante',37,2000000),
(5,'Christian',30,2500000),
(6,’Knox’,40,2000000);
SELECT * FROM employees;
CREATE TABLE emp(id INT,name VARCHAR(50),location VARCHAR(50));
INSERT INTO emp (id, name, location)
VALUES
(1,'Alex','NYC'),
(2,'Rhys','ELDORA'),
(3,'Josh','CHINA'),
(4,'Dante','RUSSIA'),
(5,'Christian','PARIS'),
(6,'ARIA','ROSEWOOD'),
(7,'MABEL’,'ARCONIA');
SELECT * FROM emp;

INNER JOIN:
SELECT e.id, e.name, e.salary, e.age, p.location FROM employees e INNER JOIN emp p on e.id=p.id;

RIGHT JOIN:
SELECT e.id, e.name, e.salary, e.age, p.location FROM employees e RIGHT JOIN emp p on e.id=p.id;

LEFT JOIN:
SELECT e.id, e.name, e.salary, e.age, p.location FROM employees e LEFT JOIN emp p on e.id=p.id;

FULL JOIN:
SELECT e.id, e.name, e.salary, e.age, p.location FROM employees e LEFT JOIN emp p on
e.id=p.id UNION ALL
SELECTe.id,e.name,e.salary,e.age,p.locationFROMemployeeseRIGHTJOINemppone.id=p.id;
OUTPUT:

Employees table:

Emp table:

INNER JOIN:
REGNO:311521205305

RIGHT JOIN:

LEFT JOIN:

FULL JOIN:

RESULT:
REGNO:311521205305

PROGRAM:

TABLE 1:

create table students(


id integer,
name varchar(20),
primary key(id)
);
insert into students(id,name) values(08,"aaa");
insert into students(id,name) values(28,"bbb");
insert into students(id,name) values(44,"ccc");
select * from students;

TABLE 2:

CREATE TABLE dep(


dname varchar(20),
id integer not null,
FOREIGN KEY (id) REFERENCES students(id)
);
insert into dep(dname,id) values("IT",08);
insert into dep(dname,id) values("ECE",28);
insert into dep(dname,id) values("CSE",44);
SELECT * FROM dep;

OUTPUT:

TABLE 2:

CREATE TABLE dep(


dname varchar(20),
id integer not null,
FOREIGN KEY (id) REFERENCES students(id)
);
REGNO:311521205305

insert into dep(dname,id) values("IT",08);


insert into dep(dname,id) values("ECE",47);
insert into dep(dname,id) values("CSE",25);
SELECT * FROM dep;

THIS WILL RAISE ERROR:(BECAUSE ID=47 IS NOT IN STUDENTS TABLE)*

OUTPUT:

RESULT:

You might also like