Professional Documents
Culture Documents
Management System
Material
-By
INDEX
1. Basics of database 03
2. SQL 05
3. Joins 09
4. Views 10
5. Embedded SQL 12
6. Transactions 13
8. Miscellaneous Questions 19
9. Sample Queries 30
Page27
BASICS OF DATABASE
1. What is a database?
DBMS is a collection of interrelated files and a set of programs that allow user to
access and modify this data.
The main aim of using DBMS is to provide a convenient and efficient way to
store, retrieve and modify information
A master file stores relatively static data about an entity and changes rarely and
where as transaction file stores relatively transient data about a particular data
processing task and changes more frequently as transactions happen more
frequently and in large numbers
Data security, data redundancy, data isolation, program/ data dependency, lack
of flexibility
The 3 levels of DBMS architecture are: External/ view level, conceptual/ logical
level and internal/ physical level
Entity is a common word anything real or abstract, about which we want to store
data.
Data base based on the E-R model may have some amount of
inconsistency, ambiguity and redundancy. To resolve these
issues some amount of refinement is required. This refinement
process is called as normalisation.
DB2- IBM
SQL
20. What is SQL?
(a) It consumes additional disk space. (b) The index table must
be updated every time a row is added to the table and every
time the indexed column is updated in existing row. This
imposes additional overhead on insert and update statements
for the table.
1. where 3. having
2. group by 4. order by
The having clause is used along with the group by clause. The
having clause can be used to select and reject row groups.
The having clause specifies condition for groups.
The union operation combines the rows from two sets of query
results. By default, the union operation eliminates duplicate
rows as part of its processing.
By using Union all we retrieve all the records from both tables
(it may have some duplicates) where as by using union all the
records from both tables and there will not be any duplicates
in query result.
The intersect operation selects the common row from two sets
of query results.
50. What is a sub query?
JOINS
52. What is a join?
Cross joins return all rows the first table. Each row from the
first table is combined with all rows from the second table.
Cross joins are also known as the Cartesian product of two
tables
VIEWS
62. What is a view?
Page27
A view is virtual table in the database defined by a query. A
view does not exist in the database as a stored set of data
values.
A joined view draws its data from two or three different tables
and presents the query results as a single virtual table. Once
the view is defined, one can use a single table query against
the view for the requests that would otherwise each require a
two or three table join.
EMBEDDED SQL
73. What is the purpose of embedded SQL?
3. No if statement to test
conditions
If one step fails, the complete transaction fails and the system
is taken back to the original state that existed before the start
of the transaction. This process of going back to the original
state is called as rollback.
(OLTP)?
In the OLTP systems, the user will be continuously interacting
with system through a computer or a terminal on a regular
basis.
1. Atomicity 3. Isolation
2. Consistency 4. Durability
All the data entered into the system must be validated for its
correctness and adherence to the organisation’s business
rules. This is implemented in RDBMS using three types of
integrity checks. Those are
1. Domain integrity
2. Entity integrity
Page27
3. Referential integrity
90. What is domain integrity check?
2. On delete set null: on delete the parent table data, set null
value in the child table wherever the deleted data is referred.
4. On delete set cascade: delete all the child table record from
the parent table on the deletion of parent record in the parent
table.
table?
To achieve consistency while supporting concurrency of
transactions.
state?
A data base may go in an inconsistent state by
1. An application error
2. Power failure
3. OS or database failure
1. Dumping
2. Cold backup
3. Hot backup
3. Memory failure
Each data ware house or data mart includes one or more fact
tables. A fact table is central to a star or snowflake schema,
and captures the data that measures the organisations
business operations. Fact tables generally contain large
number of rows.
Page27
MISCELLANEOUS QUESTIONS:
1. Define the "Integrity rules"
6. What is an attribute?
component Y.
Partial Key:
Alternate Key:
Artificial Key:
Compound Key:
Natural Key:
Types:
Ø B-Tree indexing
Ø Table indexing
Atomicity:
Either all actions are carried out or none are. Users should not
have to worry about the effect of incomplete transactions.
DBMS ensures this by undoing the actions of incomplete
transactions.
Aggregation:
Page27
A concept which is used to model a relationship between a
collection of entities and relationships. It is used when we
need to express a relationship among relationships.
processes themselves
Oracle database-wide system memory is known as the SGA,
the system global area or shared global area. The data and
control structures in the SGA are shareable, and all the Oracle
background processes and user processes can use them.
Ø The row within the block (because each block can hold
many rows)
The Export utility dumps the definitions and data for the
specified part of the database to an operating system binary
file. The Import utility reads the file produced by an export,
recreates the definitions of objects, and inserts the data
32. What are user defined data types and when you
should go for them?
User defined data types let you extend the base SQL Server
data types by
providing a descriptive name, and format to the database.
Take for
example, in your database, there is a column called
Flight_Num which
appears in many tables. In all these tables it should be
varchar(8).
In this case you could create a user defined data type called
Flight_num_type of varchar(8) and use it across all your
tables.
TABLE
also deletes all the rows in a table, but it won't log the
deletion of
each row, instead it logs the deallocation of the data pages of
the
table, which makes it faster. Of course, TRUNCATE TABLE can
be rolled
back.
In SQL Server 6.5 you could define only 3 triggers per table,
one for
INSERT, one for UPDATE and one for DELETE. From SQL Server
7.0
onwards, this restriction is gone, and you could create
multiple
triggers per each action. But in 7.0 there's no way to control
the
order in which the triggers fire. In SQL Server 2000 you could
specify
which trigger fires first or fires last using sp_settriggerorder
Till SQL Server 7.0, triggers fire only after the data
modification
operation happens. So in a way, they are called post triggers.
But in
SQL Server 2000 you could create pre triggers also. Search
SQL Server
2000 books online for INSTEAD OF triggers.
Also check out books online for 'inserted table', 'deleted table'
and
COLUMNS_UPDATED ()
object and
pass the newly inserted rows to it for some custom
processing. What
do you think of this implementation? Can this be implemented
better?
There are five aggregate system functions they are viz. Sum,
Min, Max, Avg, Count. They all have their own purpose.
Aggregate Key
What is the difference between varchar and varchar2?
Primary Key is a much similar to unique key. Only difference is
that unique key can be null but primary key cannot be null.
Primary key is used to avoid duplication of data.
DBMS includes the theoretical part that how data’s are stored
in a table. It does not relate tables with another. While RDBMS
is the procedural way that includes SQL syntaxes for relating
tables with another and handling data’s stored in tables.
DBMS doesn't show the relation while RDBMS show the
relation and moreover DBMS is for small organisations where
RDBMS for large amount of data In DBMS all the tables are
treated as different entities. There is no relation established
among these entities. But the tables in RDBMS are dependent
and the user can establish various integrity constraints on
these tables so that the ultimate data used by the user
remains correct. In DBMS there are entity sets in the form of
tables but relationship among them is not defined while in
RDBMS in each entity is well defined with a relationship set so
as retrieve our data fast and easy.
If data does not exist or does not apply then a value of NULL is
applied, this is understood by the RDBMS as meaning non-
applicable data.
• Data Definition
• View Definition
• Data Manipulation (Interactive and by program).
• Integrity Constraints
• Authorization.
Not only can the user modify data, but so can the RDBMS
when the user is not logged-in.
SAMPLE QUERIES:
1.DDL STATEMENTS.
2. DML STATEMENTS:
should be committed.
2. Delete:
It is used to delete data(rows) from the database objects.
Mainly deals with data(rows)
3. Update:
3. TCL STATEMENTS:
1. Commit:
Commit;
2. Rollback:
Rollback;
4. where clause:
Page27
1. comparator operators
2. Special operators.
Above statement retrieves all the names which start with ‘s’
1. Arithmetic functions :
2. Character functions:
3. Date functions:
4. General functions:
Select least(100,10,7,99), greatest(100,10,7,99) from dual;
6. Group by clause:
7. Having clause:
8. Order by:
9. Joins:
Page27
Here faculty, course are the two table with a single column
and fname, cname are the columns. fname is in faculty and
cname is in course.
This is called left outer join all the rows from the dept table
and common rows from the emp table
4.left+ right outer join will give you full outer join here ‘+’ will
be union operator.
Set operators
Intersect
Creating users
Here user name is yugander and hello is his pass word and
after this he should be given resource to connect . so it will be
as follows
12. SUBQUERIS
2. select * from emp where sal > any (select sal from emp
where deptno=10);
Page27
Or
In above query replace ‘any’ with ‘all’ and in the next query
min() with max() we will get max sal
This lists the employees whose sal is more than their average
salary.
2. N th max. Salary
15. CONSTRAINTS
Take one more table called incr, the attributes are empno,
amount . empno of incr references to empno of emp table.
Cascade constraints:
table is dropped.
Child rows will not be removed
Table constraints
Account_num number(5),
Cust_email varchar2(30),
It is created by DBA.
To delete a role
The query gets back the permissions from the role rahat_role
Page27