Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword or section
Like this
34Activity
P. 1
DBMS

DBMS

Ratings:
(0)
|Views: 9,101|Likes:
Published by kcmaharshi

More info:

Published by: kcmaharshi on Feb 04, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

02/28/2015

pdf

text

original

 
DATABASE MANAGEMENT SYSTEM
DBMS is software system and its main purpose is to store data but every software whichstores data is not DBMS.Characteristics of DBMS
 – 
it must provide a easy language for retrieval and manipulation of data.
Language should not have complex programming techniques and it should supportstructural programming.
Language supported by DBMS – SQL(Structured Query Language)
 – 
It must provide concurrent access to data( Multiple transaction can be performed on data ata time).
 – 
It must provide data integrity ( No replicated data). –It must provide security( prevent accessing of data by unauthorized user)DBMS store data in form of 
table
or 
relation
. A table consist of 
rows
( or 
records
or 
tuples
)and
column
(or 
field
or 
attribute
). A
Database
is collection of tables. Consider student tablegiven below.RollNoNameAddressDOB1Vivek 12, jivaji nagar18/8/872PriyeshM25-gandhinagar15/6/90In this Student table there are four columns(RollNo, Name, Address, DOB) and tworows(records). Each column is defined with a data type. Some General data types supported by DBMS are:
1.
Varchar- for string of characters2.Number- for numeric values3.Date- for date and time
Constraints
are the conditions which are required to be satisfied when data is inserted or deleted or modified. Suppose for Student table a constraint is defined to check age of studentsis not more than 20, then we can apply check for DOB > “31/12/1990”. If we try to insertentry for a student with DOB less than 31/12/1990 then insertion of record will give error andtransaction will not be completed successfully.
RDBMS
- A software system is said to be a Relational DBMS if it follows all 12 rulessuggested by E. F. Codd. Oracle follows only 7-8 rules and MS access follows only 3-4 rules.
STRUCTURED QUERY LANGUAGE
This is standard query language which should be implemented by all RDBMS for defining,manipulation and retrieval of data. SQL statements can be divided into 3 categories:
(i)
DDL
( data definition language): used to define tables. e.g. Create, Alter, Update
(ii)
DML
(data Manipulation Language): used to manipulate data in tables. e.g. insert, update,delete, select
(iii)
DCL
(data control language): e.g. Commit, rollback Uses of some component of SQL is given below:
1.
Create
: used to create a tableExample: create table Student ( Rollno Number(5),Name Varchar(20) Not Null,Address varchar(30),DOB Date )
ENGINEERS CIRCLE, GWALIORPage 1
 
This query will create a table with four fields
i.
Rollno- which is number type and 5 digit it can have at max.
ii.
Name- which is variable character string type with maximum 20 character. Not null isconstraints which specify that values in Name field cannot be null.
iii.
Address- which is variable character string type with maximum 30 character iv.DOB- which is date typeRollNoNameAddressDOB
1.
Insert:
used to Insert data into table.Example: insert into Student values (1,’Vivek’,’ 12, jivaji nagar’,’26/10/1987’ )This query will insert a tuples into table Student.RollNoNameAddressDOB1Vivek 12, jivaji nagar26/10/1987 Note: when we use varchar and date data in query then it should be in single quotes.Keywords in SQL, column names and table names are not case sensitive but data is casesensitive.If we want to insert data in particular fields then query will be asinsert into student( Rollno, Name) values (2 ,’priyesh’)now table will be:RollNoNameAddressDOB1Vivek 12, jivaji nagar18/8/872PriyeshNullNullIf we try to insert a tuple without name then query will give error in execution, because wehave defined Name field with constraint ‘not null’.Example: insert into student (Rollno) values(3);This query will generate error because null value is not accepted in Name field.
2.
Update:
used to update values in tableExample: update student set Address =’21,gandhinagar’This query will update all values in Address field to ’21,gandhinagar’RollNoNameAddressDOB1Vivek 21,gandhinagar18/8/872Priyesh21,gandhinagarNullBut if we want to change address of particular fields then we can use where clause.Example: update student set Address= ‘12,Jivajinagar’ where rollno=1This query will update address of student with rollno 1 to ‘21,gandhinagar’
3.
Delete:
used to delete rows from tableExample: delete from studentThis will delete all rows in student tableIf we want to delete particular row then we can use where clause.Example: delete from student where DOB < ‘31/12/1990’
ENGINEERS CIRCLE, GWALIORPage 2
 
This query will delete all records with date of birth less than ‘31/12/1990’.
4.
Commit:
save changes permanently to disk.Example: update student set Name=’Vikas’ where rollno=1;Commit;‘;’ is used to separate multiple statements. Commit statement make these changes permanently to disk. If you don’t commit the transactions than changes are made only inmain memory and if suddenly main memory switch off( or computer crashes) then thesechanges are not visible when you reboot computer. Generally DBMS implementsautocommit(automatically executes commit in some period of time ). 
5.
Rollback 
: undo changes since last commit.
6.
Drop
: used to delete tableExample: drop table studentThis query will removes table from the disk 
Note:
drop and create can not be rollbacked.
7.
Select:
used to view dataExample: select * from studentThis query will display all rows and column of student table.To view particular row and column where clause can be used asSelect rollno,name from student where DOB > ‘1/1/1995’This query will return only two column rollno and name of students those are born after 1/1/1995. In this type of query, records are selected first on the basis of conditions inwhere clause and then fields specified in the query will be displayed.
8.
Distinct:
used to produce non-duplicate result.Example: select distinct name from studentThis query will return name of students and if two or more students have same name thenonly one name is returned.Query: select distinct name ,address from studentThis query will give error when there are two students with same name and differentaddress.
9.
Where clause:
to understand where clause and conditions
Consider Relation Employee( empid, ename , salary, job, deptid )Q1.
write a Query to find name of all employee of deptid 10
Ans
. select ename from employee where deptid=10
Q2.
write a query to find name of all manager from deptid 20
Ans.
select ename from employee where deptid=20
and
 job= ‘Manager’
Q3.
write a query to find name of employee belongs to deptid 10 or deptid 20
Ans.
select ename from employee where deptid=10
or
deptid=20This query can be rewritten with the use of
in
’ asSelect ename from employee where deptid in(10,20)‘in’ checks for set membership. In this example ‘in’ checks whether deptid
{10,20}
Q4.
Write a query to find name of employees having salary between 1000 and 2000Ans. Select ename from employee where salary>=1000 and salary <=2000This query can be rewritten with the use of
between
’ as
ENGINEERS CIRCLE, GWALIORPage 3

Activity (34)

You've already reviewed this. Edit your review.
NehaJethani liked this
kewl3gt liked this
manubk2003 liked this
1 hundred reads
Prashant Dixit liked this
vasundhara45 added this note
thx a lot
Sayan Gupta liked this
Patel Jinal liked this
beck2ham liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->