DBMS
DBMS
DBMS
Database Managements
System
8460831302 Page 1
Database Management System
Advantages of DBMS.
1.Reduce data Redundancy
2.Data consistency
3.Data sharing
4.Database enforce standards
5.Data security
6.Data independance
SQL Terminology:-
Table:-SQL table is collection of data which is organized in terms of rows and
columns. In DBMS, the table is known as relation or entity.
8460831302 Page 2
Database Management System
Table:-Employee. Entity/Relation
Keys database:-
There are following keys in DBMS.
1.Primary key:- A primary key is a set of one or more attribute(column)
that can uniquely identify row(record/tuple) within the relation.E.g:-Emp_id
2.Candidate key:- A candidate key is combination of one of more
attribute which include primary key.E.g:-Emp_id+Ename
3.Alternate key:- A alternate key is combination of one of more
attribute which does n't include primary key. E.g:-ename+post
4.Foreign key:-A foreign key is attribute which values are derived from
other table.E.g:-Emp_id is primary key for employee table but Emp_id is foreign
key for department table.
SQL Constraints:-A database constraints is set of rules that define valid
data.DBMS ensure that all constraints satisfy before inserting new data.
There are following Constraints in MySQL.
1.Primary key
2.Unique:-It allows unique values.
3.Not NULL:-It didn't allow to left blank.
4.Check:-It will check conditions. such as marks>0 and marks<100
8460831302 Page 3
Database Management System
SQL:-
SQL stands for Structured Query Language
SQL lets you access and manipulate databases
SQL can execute queries against a database
SQL can retrieve data from a database
SQL can insert records in a database
SQL can update records in a database
SQL can delete records from a database
SQL can create new databases
SQL can create new tables in a database
SQL can create views in a database
o CREATE
o ALTER
o DROP
8460831302 Page 4
Database Management System
o TRUNCATE
o INSERT
o UPDATE
o DELETE
These operations are automatically committed in the database that's why they cannot
be used while creating tables or dropping them.
o COMMIT
o ROLLBACK
o SAVEPOINT.
Data Type:-
There are following MySQl data type.
1. Int:-Stores integer numbers. E.g :-rollno can store as int
2. Decimal:-store decimal point numbers. E.g:- price can store as decimal
3. Char:-store characters (also stores number and special charcaters). It is
static data type.e.g:-name
8460831302 Page 5
Database Management System
SQL Commands:-
1.Create database:-It is used to create new database.
Syntax:-use <databasename>;
E.g:-show databases;
4.Create table:-
Student
8460831302 Page 6
Database Management System
Try Yourself:-
Employee
E.g:-show tables;
8460831302 Page 7
Database Management System
7.4 where with between keyword:-Between is used to specify the range. Lower
8460831302 Page 8
Database Management System
7.7 where with is keyword:-is keyword is used to search for null data.
Syntax:- select * from <tablename> where <field> is NULL;
e.g:-select * from students where name is NULL;
practice question
Display all student those who are living in “Nana Varchcha” area
Display all details of student named “Shree”
Display all details of grno 2
Display all students who got more than 90 marks in IP
Display all students who got less than 20 marks in IP
Display all science students
Display all 11 std students
8460831302 Page 11
Database Management System
Student
Fieldname Datatype(Size) Constraints
Grno Int(3) Primary key
Name Varchar(25) Not null
Std Int(2)
Division Varchar(10)
Address Varchar(25)
Create table student(grno int(3)primary key,name varchar(25),std int(2),division
varchar(10),address varchar(25));
Marks
Fieldname Datatype(Size) Constraints
8460831302 Page 12
Database Management System
8460831302 Page 13
Database Management System
Group by
When you want to create group in table then search data, group by is used.
Suppose, display student areawise, you can write
Select * from student group by address;
Suppose you want to display total no of student in each std.
Select count(*) from student group by std;
Having
You cannot not used where clause with group by. Having can be used in place of
where to search data based on condition.
Suppose you want to display std where more than 50students are studying..
Select count(*) from student group by std having count(*)>50;
8460831302 Page 14