0% found this document useful (0 votes)
2 views8 pages

Day2 Live

Uploaded by

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

Day2 Live

Uploaded by

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

--diff in RDBMS and DBMS

RDBMS : the fk is present


DBMS : there is no fk

RDBMS : relationship can be created between the tables


DBMS : can not create a relationship

RDBMS : memory requirement is low


DBMS : memory requirement is high

RDBMS : speed is high


DBMS : speed is low

==============
show databases;
use cdac;
show tables;
select * from

--to break
ctrl + c

--Normalization
it is database design techique
it is used to avoid the repeatation of the data / redundancy
we break one table into 2 or more tables in Normalization
Normalization is process , which is followd by database designer or
database architecture
Normalization is performed before creating the tables or inserting the records.
there are 3 Normalization forms.
1NF : 1st normal form
a relation is said to be in “first normal form” (1NF) if and only if all its
attributes assume only atomic values.
pk : orderno+ itemno

2NF : 2nd normal form


A relation is said to be in 2NF if and only if it is in 1NF and every non-key
attribute is fully functionally dependent on the primary key.
or
remove functional dependency

3NF : 3rd normal form


remove the transitive dependency

the data will be reliable, normal, correct or believable using Normalization.

===
transitive dependency
----------------->
---------> ----->
c1 c2 c3
10 x aa
20 y bb
30 z cc
10 x aa
20 y bb

if there are 3 cols , if values of c1 depends on values of c2


and if values of c2 depends on values of c3
then c1 depends on values of c3
=====================
pk : orderno+ itemno
orderno itemno qty price cust name Address city
code
y y n n n n

=================

10.00 to 12.00 : lecture


12.20 - 1.30 : lecture
1.30 - 2.15 : lunch
2.15 - 4.15 : practice
4.15- 4.30 : tea
4.30 - 5.30 : lecture
5.30 - 8.00 : practice

==
dml : INSERT, update delete

--1st
insert into emp values ( 3 , 'ritesh' , 32000.00 , 20 , 'p003' )
insert into emp values ( 4 , 'rita' , 32000.00 , 20, null )
insert into emp values ( 5 , 'tej' , null , null, null )

--2nd method to insert a record


insert into emp (ename , empno, sal) values('tejas', 6, 40000);

--change the name as siddharth for empno 1


update emp
set ename = 'siddharth'
where empno =1;

--change the pancard as s001 for employee siddharth


update emp
set pancard= 's001'
where ename = 'siddharth';

--change the pancard as s002 for employee no 2


update emp
set pancard= 's002'
where empno=2;

--delete the record where the name as siddharth


delete from emp
WHERE ename ='SIDDHARTH';

--NOTE
the data, commands is not case sensitive

--delete the record where pancard is a null value


delete from emp
where pancard is null;

--delete the record where pancard has value


delete from emp
where pancard is not null;

null : empty
insert into emp values (1, 'vinit', 30000, 10, 'p001');
insert into emp values (2, 'vinit1', 30000, 10, 'p002');

--delete all the records


delete from emp;

--truncate
will delete all the records, but the structure will be preserved

truncate table emp ;


select * from emp;

--diff truncate and delete


truncate : ddl
delete : dml

truncate : faster than delete


delete :

truncate : will delete the rows at a time


delete : will delete the rows, rowwise

truncate : where condition can not be given


delete : where condition can be given

--diff truncate and drop


truncate : will delete all the records, but the structure will be preserved
drop : will delete records along with the structure

====
create table emp1(
empno numeric(4),
ename varchar(20),
doj date);

insert into emp1 values(1, 'yash', '2024-12-30' );


select curdate();
insert into emp1 values(2, 'yashwini', curdate());

dml : insert , update ,delete


ddl : create , drop, truncate

--to redirect the command to a file till exit


tee d:\Priti\day2_commands.txt
|
folder
select * from emp;
select * from dept;
select curdate()
select now();
select * from emp1;
exit
open -----> file --> day2_commands.txt ---> check

2.15 upto :
2.15 -4.15 : PR

select * from emp


WEHRE sal >=2000 and sal <=4000;
================================================
--to drop the table
drop table dept;
will delete all the records along with the structure

===============
--to see the current time
select current_time();

==to see the help


help
or
\h

==to execute a sql file


source d:\priti\file1.sql

truncate table emp;


file : d:\priti\file1.sql --select all files
insert into emp values (1, 'vinit', 30000, 10, 'p001');
insert into emp values (2, 'nita', 30000, 10, 'p002');
insert into emp values (3, 'sita', 30000, 10, 'p003');

===========
--to give the comments in mysql
--single line comments
#sdlfksldfk

--multiple line comments


/* sdflsdkfsd
sdf
sd
fsdf */

--emp dept file


source d:\priti\EMP_DEPT_Script.sql

or
google : emp dept script mysql

===========
--display empno ,ename ,job,
select empno ,ename ,job from emp;
desc emp;
select job from emp;

--to avoid the repeatation, or to supress the duplication of values


select distinct job from emp;
select distinct deptno from emp;

--to display all the emp details who are receiving the comm
select * from emp
where comm is not null;

--to display all the emp details who are not receiving the comm
select * from emp
where comm is null
or comm=0;

select * from emp


where comm is null
|| comm=0;

--logical operators
and &&
or ||
not !=

--relational operators
>
<
>=
<=
=
!=
<>

--airthmatic operators
+
-
*
/

--display ename who are not from deptno 10


select ename from emp
where deptno != 10;

select ename from emp


where deptno <> 10;

--display ename whoes sal > 1000 and who are from deptno 20
select ename from emp
where sal > 1000 and deptno=20;
---------- ----------
1 2

select ename from emp


where sal > 1000 && deptno=20;

select ename from emp


where sal > 1000 and deptno=20 and comm is null and job='manager';

--display ename whoes sal > 1000 or who are from deptno 20
--4
select ename from emp
where sal > 1000 and deptno=20;

--13
select ename from emp
where sal > 1000 or deptno=20;

--display the all details for smith , jones and allen


select * from emp
where ename ='smith' or
ename ='jones' or
ename ='allen'
--or
select * from emp
where ename in ('smith', 'jones', 'allen')

--display the all details who are working for deptno 10, 20
select * from emp
where deptno =10 or deptno=20

select * from emp


where deptno in (10, 20)

--display the all details who are manager or analyst and whoes sal > 2000
select * from emp
where job in ('manager', 'analyst') and sal > 2000;

--display the all details who are manager , in deptno 10 and who are salesman from
20
select * from emp
where (job='manager' and deptno=10) or (job='salesman' and deptno=20)

--predicates
1 in : exact match
2 between : range
3 like : search for pattern

--tomo
not int
between
like
data types
ER diagrams
aggr fun
constraints
alter

You might also like