Вы находитесь на странице: 1из 13

What is DBMS ?

DBMS Stands for "Database Management System." The DBMS is a software package with computer
programs. A DBMS is a database program. Technically speaking, it is a software system that uses a
standard method of cataloging, retrieving, and running queries on data. The DBMS manages incoming
data, organizes it, and provides ways for the data to be modified or extracted by users or other programs.
A database is an integrated collection of data records, files, and other objects. DBMSs may use a variety
of database models, such as the relational model , hierarchical model and network model. Some DBMS
examples are, MySQL, PostgreSQL, Microsoft Access, SQL Server, FileMaker, Oracle, RDBMS,
dBASE, Clipper, and FoxPro.
What is RDBMS ?
RDBMS, stands for Relational Database Management System is an information system that presents
information as rows contained in a collection of tables, each table possessing a set of one or more
columns . The data can be accessed or reassembled in many different ways without having to change the
table forms. E. F. Codd described the elements of a relational database as relation, attributes, domains and
the relation operators.

The term relation is used to describe these tables which is a more precise way of defining than the
traditional data processing term file or table.
What is difference between DBMS and RDBMS ?
RDBMS can be made a server. It connects more systems but DBMS works only woke in host system,
RDBMS have Normalization. Normalization means to refining the redundant and maintain the
stabilization. the DBMS hasn't normalization concept.
DBMS is a broad area of database maintenance that also involves other database model as network
model, object oriented database model and relation model. Here the relation model is called RDBMS.
RDBMS stores data in the form of tables(collection of rows and columns). Normalization makes
information non redundant.
DBMS is a single user database, it does not support E.F.Codd rules and does not allow relationship
between tables. RDBMS is a multi user database ,it supports E.F.Codd rules and it allows relationship
between tables
What is entity ?
An entity is any object, place, person, concept, activity about which an enterprise records data. It is an
object which can have instances or occurrences. Each instance should be capable of being uniquely
identified. Each entity has certain properties, or attributes associated with it and operations applicable to
it.
What is an Attributes ?
An attributes are data elements that describe an entity. If the attribute of an entity has more attributes that
describe it, then it is not an attribute of that entity, but another entity. Attributes can either either be listed
next to the entities, or placed in circles and attached to the entities.
Explain one-to-one relationship with an example ?
For one occurrence of the first entity there can at most one related occurrences of the second entity and
for one occurrence of the second entity there can be at most one related occurrence of the second entry.
For example, the Order and Purchase table, one Order Requisition raises one purchase order and one
purchase order is raised by one order requisition.
Explain one-to-many relationship with an example ?
In one-to-many relationships data into two tables with a primary key and foreign key relationship can be
implemented. For one occurrence of the first entity there can exist many related occurrences of the second
entity and for every occurrence of the second entity there exists only one associated occurrence of the
first. For example, the Employees and Departments table, where the row in the Departments table is
referenced by one or more rows in the Employees table. So, in one-to-many relationship - one employee
works in at most one department but one department can have many employees.
Explain many-to-many relationship with an example ?
For one occurrence of the first entity many related occurrences of second entity may be exists and also for
every occurrence of the second entity many associated occurrences of first entity may be exists.
For example, suppose we have two table order and item - from here we can explain this relationship such
a way that, one order may contain many items and one item can be contained in may orders.
What is View ?
In RDBMS , a view is a virtual table because it does not exist in its own right, but appears to the user as if
it did. A base table is a real table that exists in physical storage. A view does not have its own physically
stored data but derives the data from the table it is associated with. It manipulates data in the underlying
base table.
Views restricts access to the database. SELECTing from a view can display a restricted portion of the
database.
As a view does not store any data, the redundancy problem does not arise. VIEWS allows users to make
simple queries to retrieve the results from complicated queries.

DDL

Data Definition Language (DDL) statements are used to define the database structure or schema. Some
examples:
o CREATE - to create objects in the database
o ALTER - alters the structure of the database
o DROP - delete objects from the database
o TRUNCATE - remove all records from a table, including all spaces allocated for the records are
removed
o COMMENT - add comments to the data dictionary
o RENAME - rename an object
DML

Data Manipulation Language (DML) statements are used for managing data within schema objects.
Some examples:
o SELECT - retrieve data from the a database
o INSERT - insert data into a table
o UPDATE - updates existing data within a table
o DELETE - deletes all records from a table, the space for the records remain
o MERGE - UPSERT operation (insert or update)
o CALL - call a PL/SQL or Java subprogram
o EXPLAIN PLAN - explain access path to data
o LOCK TABLE - control concurrency
DCL

Data Control Language (DCL) statements. Some examples:
o GRANT - gives user's access privileges to database
o REVOKE - withdraw access privileges given with the GRANT command
TCL

Transaction Control (TCL) statements are used to manage the changes made by DML statements. It
allows statements to be grouped together into logical transactions.
o COMMIT - save work done
o SAVEPOINT - identify a point in a transaction to which you can later roll back
o ROLLBACK - restore database to original since the last COMMIT
o SET TRANSACTION - Change transaction options like isolation level and what rollback
segment to use

What is the difference between VARCHAR and CHAR data types?

CHAR
1 used to store character string value of fixed length.
2 the maximum no of character that data type can hold is 255 character .
3 Char is 50% faster than varchar.
4 use the Static memory allocation .
VARCHAR
1 used to store variable length alphanumeric data.
2 The maximum this data type can hold upto 4000 character .
3 it's slower than the Char.
4 use the dynamic memory allocation .
Metadata

The term metadata refers to "data about data". The term is ambiguous, as it is used for two
fundamentally different concepts (types). Structural metadata is about the design and specification
of data structures and is more properly called "data about the containers of data"; descriptive
metadata, on the other hand, is about individual instances of application data, the data content.
Metadata are traditionally found in the card catalogs of libraries. As information has become
increasingly digital, metadata are also used to describe digital data using metadata standards
specific to a particular discipline. By describing the contents and context of data files, the quality of
the original data/files is greatly increased. For example, a webpage may include metadata specifying
what language it is written in, what tools were used to create it, and where to go for more on the
subject, allowing browsers to automatically improve the experience of users.

Database schema
schema of a database system refers to the organization of data as a blueprint of how a database is
constructed (divided into database tables in case of Relational Databases). The formal definition of
database schema is a set of formulas (sentences) called integrity constraints imposed on a
database. These integrity constraints ensure compatibility between parts of the schema. All
constraints are expressible in the same language. A database can be considered a structure in
realization of the database language.[1] The states of a created conceptual schema are transformed
into an explicit mapping, the database schema. This describes how real world entities are modeled
in the database.

Data dictionary

A data dictionary is a part of the metadata that is used to understand the data and the databases that
contain it. The data dictionary identifies data elements and their attributes including names, definitions
and units of measure and other information. Often they are organized as a table. The focus here is on the
need to adopt and support more consistent use of data dictionary elements and terminology as a part of
improving metadata.

Data dictionary is used to actually control the database operation, data integrity and accuracy.
Metadata is used by developers to develop the programs, queries, controls and procedures to
manage and manipulate the data. Metadata is available to database administrators (DBAs),
designers and authorized user as on-line system documentation. This improves the control of
database administrators (DBAs) over the information system and the user's understanding and use
of the system.

Importance of Data Dictionary
Data dictionary is essential in DBMS because of the following reasons:
Data dictionary provides the name of a data element, its description and data structure in which it may
be found.
Data dictionary provides great assistance in producing a report of where a data element is used in all
programs that mention it.
It is also possible to search for a data name, given keywords that describe the name. For example, one
might want to determine the name of a variable that stands for net pay. Entering keywords would produce
a list of possible identifiers and their definitions. Using keywords one can search the dictionary to locate
the proper identifier to use in a program.


Database: A collection of related data.
Data: Known facts that can be recorded and have an implicit meaning.
Mini-world: Some part of the real world about which data is stored in a database. For
example, student grades and transcripts at a university.
Database Management System (DBMS): A software package/ system to facilitate the
creation and maintenance of a computerized database.
Database System: The DBMS software together with the data itself. Sometimes, the
applications are also included.
Data Model: Describe the structureof a database, and certain constraints that the database
should obey.
Entities and Attributes
Entities are specific objects or things in the mini-world that are represented in the
database. For example the EMPLOYEE John Smith, the Research DEPARTMENT,
the ProductX PROJECT
Attributes are properties used to describe an entity. For example an EMPLOYEE
entity may have a Name, SSN, Address, Sex, BirthDate
A specific entity will have a value for each of its attributes. For example a specific
employee entity may have Name='John Smith', SSN='123456789', Address ='731,
Fondren, Houston, TX', Sex='M', BirthDate='09-JAN-55
Each attribute has a value set (or data type) associated with it e.g. integer, string,
subrange, enumerated type,
Types of Attributes
Simple
Each entity has a single atomic value for the attribute. For example, SSN or Sex.
Composite
The attribute may be composed of several components. For example, Address (Apt#,
House#, Street, City, State, ZipCode, Country) or Name (FirstName, MiddleName,
LastName). Composition may form a hierarchy where some components are
themselves composite.
Multi-valued
An entity may have multiple values for that attribute. For example, Color of a CAR
or PreviousDegrees of a STUDENT. Denoted as {Color} or {PreviousDegrees}.
Entity Types and Key Attributes
Entities with the same basic attributes are grouped or typed into an entity type. For
example, the EMPLOYEE entity type or the PROJECT entity type.
An attribute of an entity type for which each entity must have a unique value is called a key
attribute of the entity type. For example, SSN of EMPLOYEE.
A key attribute may be composite. For example, VehicleTagNumber is a key of the CAR
entity type with components (Number, State).
An entity type may have more than one key. For example, the CAR entity type may have
two keys:
VehicleIdentificationNumber (popularly called VIN) and
VehicleTagNumber (Number, State), also known as license_plate number.
Weak Entity Types
An entity that does not have a key attribute
A weak entity must participate in an identifying relationship type with an owner or
identifying entity type
Entities are identified by the combination of:
A partial key of the weak entity type
The particular entity they are related to in the identifying entity type
Example:
Suppose that a DEPENDENT entity is identified by the dependents first name and birhtdate, and
the specific EMPLOYEE that the dependent is related to. DEPENDENT is a weak entity type with
EMPLOYEE as its identifying entity type via the identifying relationship type DEPENDENT_OF

FORMAL DEFINITIONS
A tuple is an ordered set of values
Each value is derived from an appropriate domain.
Each row in the CUSTOMER table may be referred to as a tuple in the table and would
consist of four values.
<632895, "John Smith", "101 Main St. Atlanta, GA 30332", "(404) 894-2000">
is a tuple belonging to the CUSTOMER relation.
A relation may be regarded as a set of tuples (rows).
Columns in a table are also called attributes of the relation.
Informal
Terms
Formal Terms
Table Relation
Column Attribute/Domain
Row Tuple
Values in
a column
Domain
Table
Definition
Schema of a
Relation
Populated
Table
Extension

Relational Integrity Constraints
Constraints are conditions that must hold on all valid relation instances. The main types of
constraints are:
1. Domain constraints
2. Key constraints
3. Entity integrity constraints
4. Referential integrity constraints
Domain constraints specify tht the value of each attribute A must be an atomic value from the
domain dom(A)
The data types associated with domains typically include integer, float and character also
date, time and money data types.
Eg- roll no 1 to 50 cant have 60 roll no

Key constraints
Superkey of R: A set of attributes SK of R such that no two tuples in any valid relation
instance r(R) will have the same value for SK.
If a relation has several candidate keys, one is chosen arbitrarily to be the primary key. The
primary key attributes are underlined.
Eg House front door and backdoor key.
Eg- pan no, emp id. To calculate slary we need emp id not pan no

Entity integrity constraints
Entity Integrity: The primary key attributes of a tuple can never be null

Referential integrity constraints
A constraint involving two relations
Used to specify a relationship among tuples in two relations: the referencing relation and
the referenced relation.
Tuples in the referencing relation R
1
have attributes FK (called foreign key attributes) that
reference the primary key attributes PK of the referenced relation
In any given relation a set of attributes is called a foreign if following rules hold
The attribute in the foreign key has to be the same as the primary key in other relation
For every tuple in the referencing relation like department the attributes in its foreign key
refer to existing tuples like each department should have a manager who exist in the
database or it should be null

Super Key
A Super key is any combination of fields within a table that uniquely identifies each record within that
table.
Candidate Key
A candidate is a subset of a super key. A candidate key is a single field or the least combination of
fields that uniquely identifies each record in the table. The least combination of fields distinguishes a
candidate key from a super key. Every table must have at least one candidate key but at the same
time can have several.

As an example we might have a student_id that uniquely identifies the students in a student table.
This would be a candidate key. But in the same table we might have the students first name and last
name that also, when combined, uniquely identify the student in a student table. These would both
be candidate keys.
In order to be eligible for a candidate key it must pass certain criteria.
It must contain unique values
It must not contain null values
It contains the minimum number of fields to ensure uniqueness
It must uniquely identify each record in the table
Once your candidate keys have been identified you can now select one to be your primary key
Primary Key
A primary key is a candidate key that is most appropriate to be the main reference key for the table.
As its name suggests, it is the primary key of reference for the table and is used throughout the
database to help establish relationships with other tables. As with any candidate key the primary key
must contain unique values, must never be null and uniquely identify each record in the table.
As an example, a student id might be a primary key in a student table, a department code in a table
of all departments in an organisation. This module has the code DH3D 35 that is no doubt used in a
database somewhere to identify RDBMS as a unit in a table of modules. In the table below we have
selected the candidate key student_id to be our most appropriate primary key

Primary keys are mandatory for every table each record must have a value for its primary key. When
choosing a primary key from the pool of candidate keys always choose a single simple key over a
composite key.
Foreign Key
A foreign key is generally a primary key from one table that appears as a field in another where the
first table has a relationship to the second. In other words, if we had a table A with a primary key X
that linked to a table B where X was a field in B, then X would be a foreign key in B.
An example might be a student table that contains the course_id the student is attending. Another
table lists the courses on offer with course_id being the primary key. The 2 tables are linked through
course_id and as such course_id would be a foreign key in the student table.

Secondary Key or Alternative Key
A table may have one or more choices for the primary key. Collectively these are known as
candidate keys as discuss earlier. One is selected as the primary key. Those not selected are known
as secondary keys or alternative keys.
For example in the table showing candidate keys above we identified two candidate keys, studentId
and firstName + lastName. The studentId would be the most appropriate for a primary key leaving
the other candidate key as secondary or alternative key. It should be noted for the other key to be
candidate keys, we are assuming you will never have a person with the same first and last name
combination. As this is unlikely we might consider fistName+lastName to be a suspect candidate key
as it would be restrictive of the data you might enter. It would seem a shame to not allow John Smith
onto a course just because there was already another John Smith.
Simple Key
Any of the keys described before (ie primary, secondary or foreign) may comprise one or more
fields, for example if firstName and lastName was our key this would be a key of two fields where as
studentId is only one. A simple key consists of a single field to uniquely identify a record. In addition
the field in itself cannot be broken down into other fields, for example, studentId, which uniquely
identifies a particular student, is a single field and therefore is a simple key. No two students would
have the same student number.
Compound Key
A compound key consists of more than one field to uniquely identify a record. A compound key is
distinguished from a composite key because each field, which makes up the primary key, is also a
simple key in its own right. An example might be a table that represents the modules a student is
attending. This table has a studentId and a moduleCode as its primary key. Each of the fields that
make up the primary key are simple keys because each represents a unique reference when
identifying a student in one instance and a module in the other.
Composite
A composite key consists of more than one field to uniquely identify a record. This differs from a
compound key in that one or more of the attributes, which make up the key, are not simple keys in
their own right. Taking the example from compound key, imagine we identified a student by their
firstName + lastName. In our table representing students on modules our primary key would now be
firstName + lastName + moduleCode. Because firstName + lastName represent a unique reference
to a student, they are not each simple keys, they have to be combined in order to uniquely identify
the student. Therefore the key for this table is a composite key.


Question : Write an SQL Query to find employee whose Salary is equal or greater than 10000.

Answer : SELECT EmpName FROM Employees WHERE Salary>=10000;

Question : Write an SQL Query to find name of employee whose name Start with M

Ans: SELECT * FROM Employees WHERE EmpName like 'M%';

Question : find all Employee records containing the word "Joe", regardless of whether it was
stored as JOE, Joe, or joe.

Answer : SELECT * from Employees WHERE upper(EmpName) like upper('joe%');

Вам также может понравиться