RDBMS Notes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

use akshita;

create table crazy (

id int primary key ,

name varchar(50),

age int not null

);

select * from crazy

where id >1;

insert into crazy ( id,name,age )

values( 1,' a ',5 );

insert into crazy ( id,name,age )

values( 1,' a ',5 );

DELETE FROM crazy WHERE id = 1;

insert into crazy ( id,name,age )

values( 5,' g ',9 );

UPDATE crazy SET age = 10 WHERE id = 1;

create database dates;

use dates;

create table dada(

id int,

name varchar(20),

join_date varchar(20)

);

insert into dada (id,name,join_date)

values(5,'deep','2004-07-05');

select* from dada;

insert into dada (id,name,join_date)


values(8,'dee',to_date('2001-07-01','yyyy-mm-dd'));

INSERT INTO dada (id, name, join_date)

VALUES (8, 'dee', TO_DATE('2001-07-01', 'yyyy-mm-dd'));

INSERT INTO dada (id, name, join_date)

VALUES (8, 'dee', STR_TO_DATE('2001-07-01', '%Y-%m-%d'));

INSERT INTO dada (id, name, join_date)

VALUES (80, 'de', STR_TO_DATE('2-07-2101', '%m-%d-%y'));

create table std16(id int,ns varchar(30), subj varchar(30))

as select * from stdu;

CREATE TABLE std12 AS SELECT * FROM stdu;

select * from std12;select * from stdu;

commit;

savepoint s5;

truncate table std12;

describe std12;

rollback s5;

drop table std12;

describe std12;

create table emp(id int,name varchar(20),debt varchar(20),salary int,state varchar(20));

insert into emp (id,name,debt,salary,state)

values (1,'aman', 'hr',1000,'gj'),

(2,'bob', 'hr',1000,'gj'),

(3,'chetan', 'hr',1000,'mh'),

(4,'diya', 'hr',1000,'mh'),

(5,'eisha', 'hr',1000,'rj'),

(6,'faishal', 'hr',1000,'rj'),

(7,'gagan', 'hr',1000,'rj'),

(8,'hari', 'hr',1000,'pj');

select * from emp;


select name from emp where state ='rj' or state ='pj'or state ='gj'

select name from emp where state in('gj','pj','mh');

select name from emp where debt in('hr' , 'it');

use learner;

select name from emp where id between 5 and 10;

select name from emp where name like '%a%';

select name from emp where name like 'd___';

select name from emp where name like '___';

select name from emp where name like '%engg%';

select name from emp where name like '___%';

select name from emp where name like '_s%';

drop table emp;

create table emp;

insert into emp (id,name,debt,salary,state)

values (1,'aman', 'hr',1000,'gj'),

(2,'bob', 'hr',1000,'gj'),

(3,'chetan', 'hr',1000,'mh'),

(4,'diya', 'it',1000,'mh'),

(5,'eisha', 'it',1000,'rj'),

(6,'faishal', 'it',1000,'rj'),

(7,'gagan', 'manag',1000,'rj'),

(8,'hari', 'manag',1000,'pj');

select name from emp where debt like 'hr';

SELECT COUNT(*) AS total_employees_with_hr_debt

FROM emp

WHERE debt LIKE '%hr%';

select debt, count(debt),"total"

from emp

group by debt;

select debt,count(debt),"t"

from emp
group by state;

select state, count(state),"total"

from emp

group by state;

select debt, count(debt),"total"

from emp

group by debt

having debt !='hr';

create table std16(id int,ns varchar(30), subj varchar(30))

as select * from stdu;

CREATE TABLE std12 AS SELECT * FROM stdu;

select * from std12;select * from stdu;

commit;

savepoint s5;

truncate table std12;

describe std12;

rollback s5;

drop table std12;

describe std12;

create table emp(id int,name varchar(20),debt varchar(20),salary int,state varchar(20));

insert into emp (id,name,debt,salary,state)

values (1,'aman', 'hr',1000,'gj'),

(2,'bob', 'hr',1000,'gj'),

(3,'chetan', 'hr',1000,'mh'),

(4,'diya', 'hr',1000,'mh'),

(5,'eisha', 'hr',1000,'rj'),

(6,'faishal', 'hr',1000,'rj'),

(7,'gagan', 'hr',1000,'rj'),

(8,'hari', 'hr',1000,'pj');
select * from emp;

select name from emp where state ='rj' or state ='pj'or state ='gj'

select name from emp where state in('gj','pj','mh');

select name from emp where debt in('hr' , 'it');

use learner;

select name from emp where id between 5 and 10;

select name from emp where name like '%a%';

select name from emp where name like 'd___';

select name from emp where name like '___';

select name from emp where name like '%engg%';

select name from emp where name like '___%';

select name from emp where name like '_s%';

drop table emp;

create table emp;

insert into emp (id,name,debt,salary,state)

values (1,'aman', 'hr',1000,'gj'),

(2,'bob', 'hr',1000,'gj'),

(3,'chetan', 'hr',1000,'mh'),

(4,'diya', 'it',1000,'mh'),

(5,'eisha', 'it',1000,'rj'),

(6,'faishal', 'it',1000,'rj'),

(7,'gagan', 'manag',1000,'rj'),

(8,'hari', 'manag',1000,'pj');

select name from emp where debt like 'hr';

SELECT COUNT(*) AS total_employees_with_hr_debt

FROM emp

WHERE debt LIKE '%hr%';

select debt, count(debt),"total"

from emp

group by debt;

select debt,count(debt),"t"
from emp

group by state;

select state, count(state),"total"

from emp

group by state;

select debt, count(debt),"total"

from emp

group by debt

having debt !='hr';

select state, count(state),"total"

from emp

where salary = 1000

GROUP BY state;

SELECT state, COUNT(state) AS total

FROM emp

WHERE salary = 1000

GROUP BY state

HAVING COUNT(state) > 1

order by state asc ;

You might also like