Database Basics
Database Basics
Database Basics
DBMS - Database Management System - reverse - A system which Mnage the Database
each&every DBMS has one Database Handler - for handle/manage the all
database operations.
like - delete / update / insert / alter / drop / create.
RDBMS - Relational Database Management System - table link with each others - with
keys \
Primary key & foreign key.
Datatabase Archi -
1. Hierarchical Database Management System - out dated - not success - tree like
structure.
2. Relational Database Management System - More Success - Database table linked
with each other - link with keys - primary key (parent) & foreign key (childs)
3. Network Database Management System - flop - more complex - concept of
pointers.
E.F. Codd's - DBMS & RDBMS - Rules - 12 Rules + 1 rule extra(Zero Rule) - 13 Rules
DELETE TRUNCATE
* DELETE ROW BY ROW * DELETE ALL RECORD IN ONE TIME.
* RECORD DELETED, BUT MEMORY EXIST. * DELETE RECORD & MEMORY BOTH.
* WE CAN ROLLBACK AFTER DELETE * WE CAN'T ROLLBACK AFTER TRUNCATE
* SLOW * FAST
* PART OF DML * PART OF DDL
WHERE HAVING
* use with select statement(just after select) * use with Group by Statement.
* single row condition * group condition
* group funcrtions not allowed. * only group function allowed
(we can't use without group by.)
-- list of all employees whose sal > 10000
select * from emp
where sal > 10000;
1. sys/pass at install time - whole control of database , like CEO - Modi Ji(PM)
Database Management - create/alter/drop/startup / shutdown
User Management - user create / drop /alter/ lock / unlock / privilege
assign / remove
Table Management
shortcut for connect with sys user - only for windows Administrator user.
SQL>connect / as sysdba
SQL>show user
2. system/pass at install time - less control of sys user, like Manager - Yogi
Ji(CM)
User Management - user create / drop /alter/ lock / unlock / privilege
assign / remove
Table Management
connect system/agile
-- to change the user password, normal user can change only own password, but dba
user can change the any user password.
** one table can contain only one primary key, but one primary key can contain
multiple columns that is called composite primary key
** we can insert null values in unique & reference key but can't insert null
values
in primary key.
** we can't insert record in foreign key without primary key values, means child
record me insert karne se pahle unka primary key table me record hoona chahiye
Emp - empno = 1001 , we can insert 1001 record in increment table,
but 1002 ka incr table me record insert nahi kar sakte bcos 1002 ka
record
pahle emp table me insert karna hooga
** we can't disable primary key & unique constraints.
constraint name - Oracle server define & user define -
with on delete casecade - if parent record deleted then child record auto deleted,
else
1st delete the child record then parent record deleted...
On delete cascade example - Employee Management System - if emp record deleted
from
emp table then all child record from related table auto
deleted.
without On delete cascade example - Student Management System.
Auto commit -
* before any DDL statement execute. - Data Definition- create / drop / alter
* before user switch / logout.
* exit with exit command.
Explicit commit - with commit command.
SQL>commit;
roolback -
Auto Rollback -
* exit with exit/close button
* after any type of Abnormal condition. - Network problem / PC Hangup / any
abnormal
Explicit rollback - with rollback command
SQL>rollback;
Q- we want to change the constraint condition, sal constraint - sal > 20000 but
now we
want to set sal > 10000
create table aa as select empno,ename,sal from emp2; - table create with data
create table aa1 as select empno,ename,sal from emp2 where 5 = 2; - table create
without data
create table aa2(roll,name,marks) as select empno,ename,sal from emp2; - table
create with diff col name
SQL> delete from emp where rowid not in(select min(rowid) from emp group by empno);