Practical List of DBMS: and Indices
Practical List of DBMS: and Indices
Definition of DBMS
Feature s of DBMS
Advantages
Definition of RDBMS
Feature s of RDBMS
Advantages
Definition of DBMS
Feature s of DBMS
Advantages
Conclusion:
Experiment no.: 2 Date:
Introduction:
The schema data Definition Language (DDL) is used for describing a database which
maybe shared by many programs written in many languages. This description is it terms
of the names and characteristics of the data items, data aggregates, records, areas. And
sets included in the database, and the relationships that exist and must be maintained
between occurrences of these elements in the database. 1 data items. A data item is an
occurrence of the smallest unit of named data. It is represented in a database by a value.
Theory:-
ALTER TABLE statement will allow you to add new column or constraint, modify
existing column or constraint, and drop existing constraint after the table is created. The
following will add a middle name column to the employees table.
The statement bellow modifies the last name to required column. This statement works
when there no null last name exist now.
Adding and deleting constraints are similar to these of the column. Here is an statements
to add a forgin key to employee table.
ALTER TABLE employees
ADD FORGIN KEY (department_id) NUMBER REFERENCES. Department
To delete a column or constraints use DROP followed by the column or constraints name
in the position of ADD or MODIFY.
Constraints can be turned off temporarily instead of dropping it, by using
DISALBLE/ENABLE clause within the alter table statements. The bellow statements
turn off the primary key for employee table. ENABLE is used when turning it on.
ALTER TABLE employees DISALBLE PRIMARY KEY;
Conclusion :
Experiment no.: 3 Date:
Theory:
The basic data Manipulation functions in these specifications include the functions
required to: . Select records 1 Present recodes to the run unit. Add new records and
relationships. Change existing records and relationships. Remove existing records and
relationships.
Insert statement
insert -statement:
INSERT INTO table name [column- identifier-comma-list)] VALUES (column-value-
comma-list)
Delete statement
delete - statement :
Update statement
update - statement:
We created the table, define the constraints and now they are ready to be populated was
data INSERT command is used to populate the table with records. Here is a statement
that adds a row or record to product table. This type of statement needs all the column to
be exact order. This is a poor way to insert values into a table.
Here is a more favorable and controllable way to insert values into the a table.
Conclusion:
Experiment no.: 4 Date:
Theory:
SQL SELECT
What do we use SQL for? Well, we use it to select data from the tables located in a
database. Immediately, we see two keywords: we need to SELECT information FROM a
table. We have the most basic SQL structure:
To illustrate the above example, assume that we have the the following table:
We shall use this table as an example throughout the tutorial (This table will appear in all
sections). To select all the stores in this table, we key in,
Result:
Store name
Los Angeles
San Diego
Los Angeles
Boston
Multiple column names can be selected, as well as multiple table names.
SQL DISTINCT
The SELECT keyboard allows us to grab all information from a column (or columns)
On a table. This, of course, necessarily mean that there will be redundancies. What if we
only want to select each DISTINCT elements? This is easy to accomplish in SQL. All we
need to do is to add DISTINCT after SELECT. The syntax is as follows:
we key in,
Result:
Store name
Los Angeles
San Diego
Los Angeles
Boston
The SELECT statement can be used to retrieve data from any or all columns from a table.
Say that you have a table called product, which consists product name, description, price,
and etc. This is the statement to retrieve all the columns from the table product.
How about if we want search product by specific chrematistics? That is when WHERE
clause becomes handy. Where clause is used when only a subset of all the rows in a table
Is required. Here is how you would list the name the price of the products has the price
valueless than $100.
There are times you want list items by conditioning two or more characteristics. For
example, if you want list product that are more than $100 or less than $50. here is bow
you would accomplish it.
The above statements will display product that are less than or greater then $1000.
Logical operators AND and OR is used in SQL as we them in English language. And will
result true when both conditions are met while OR will result true when either conditions
is true.
When you finding an string value, you cant sure the correct spelling. For example Printer
can also be printer, PRINTER, or printers. There are more ways to solve this problem
include, changing the column to upper case characters, or using LIKE statements. The
LINK operator provides pattern matching for character data and uses that is position
detention. Here is an example that uses like operator.
This will display all the products that start scan. It could be scan, scanner, scanners, scan
camera, etc. To list aall the items that has the word scan in it, we rephrase the statement
like this; WHERE name LIKE %scan%
BETWEEN operator can be used in numeric values to compare column against a range of
inclusive values. This is one example all the products between $50 and $100 inclusive.
The retrieved data may not be in any specific order unless other ways specified. Data can
be sorted using ORDER BY clause in the select statement.
This example simply lists product name, description, and the price sorted in descending
order and name in ascending order. The column aliases display more
Understandable column headers instead of actual column names.
Retrieving Calculated fields
You can perform mathematical calculations while retrieving data from tables or views.
The math operators for sql are same as those of other languages, like +,-, *, / , etc.
Say that you want calculates and display the profit of each item in the product table. The
profit price minus cost. Here is how you would do that:
This example displays list of each products information plus calculated filed that
displays item profit [ price cost]
Conclusion:
Experiment no.: 5 Date:
Theory:
Number Functions
If
SELECT CONCAT (frist_name = John,
Concatenates two (frist_name, last_name) last_name =
CONCAT(string1, string2)
strings FROM employees; Morgan)
Result is John,
Morgan
SELECT INITCAP If
Returns strings
(frist_name) (frist_name = John)
INITCAP(string) with first letter in
FROM employees; Result is John
upper case
SELECT LENGTH If
Returns an integer
(frist_name) (frist_name = John)
LENGTH (string) representing the
FROM employees; Result is 4
string length
Returns the string If price = 100
SELECT LPAD (price, 7,* )
padding Result is **** 100
LPAD (string,#,Padding_char) FROM product
Characters added to
WHERE product_id = 1;
the left
Returns the string SELECT RPAD (price, 7,* If price = 100
padding ) Result is 100****
RPAD (string,#,Padding_char)
Characters added to FROM product
the right WHERE product_id = 1;
SELECT LTRIM If
LTRIM(string,serachSrting) Remove character
(frist_name, j) (frist_name = John)
RTRIM(string,serachSrting) from left/ right of
FROM employees; Result is John
char
WHERE employees _id = 1;
REPLACE returns If
SELECT REPLACE
char with every (frist_name = John)
(frist_name, jH)
REPLACE (string,serachSrting, replacement) occurrence of Result is Hohn
FROM employees;
search String
WHERE employees _id = 1;
replacement String
SELECT SUBSTR If
Returns substring
(frist_name, 13) (frist_name = John)
SUBSTR(string,start,length) starting at start and
FROM employees; Result is Joh
of specified length
WHERE employees _id = 1;
SELECT UPPER If
Returns string with
UPPER(string) (frist_name,) (frist_name = John)
all upper/ lower
Lower(string) FROM employees; Result is JOHN
case characters
WHERE employees _id = 1;
Concatenation and column alias
You can manipulate the retrieved data by joining two columns or changing the column
heading. The default heading is actual column name. For example, when you select
product_id from product, the heading is product ip_, We can change the column heading
to product ID by using following syntax:
SELECT column_name column_alias
FROM table_name;
The following example change and display column heading of product_id as Product ID,
and column heading of name as Product Name.
This example changes the column heading of product_id and name to proper more
understandable column headings
We can also concatenate two or more fields together in select statement. For instance, if
we want join frist_name and last _name together to make up full_name, we can easily do
this using following syntax:
SELECT column_name || column_name FROM table_name; or SELECT
CONCAT(column_name, column_name) FROM table_name; Both methods accomplish
same results. The following example retrieves concatenated first_name and last name
with space between and column heading of Full Name:
There are number of string manipulation functions available for use of character output
like the CONCAT we saw. The following are list of those functions with description,
example and result:
All sql data can manipulated on retrieval or displayed as you desire it to be displayed The
date functions we are discussing next can be used to manipulate date data types. For
example, if you want to add few days, month, years to the current date or format the
output of the dates retrieved by select statement. This can done using date functions.
The following are some list of date functions available in sql:
Function Description Example Result
If (today = 1.01 2002)
SELECT sysdate
Returns current Result is 1-jan- 02
SYSDATE FROM dual;
date
Conclusion:
Experiment no.: 6 Date:
Theory:-
Group Functions
To use a group function in a SQL query, list the function name followed by numeric
column name within parentheses. AVG averages the column, COUNT counts the number
of items, MAX returns maximum number of the column, and MIN returns minimum
number of the column .
The following is query to retrieve total price, average price, maximum price, and
minimum price from the table product assuming the product table has the following
values.
SELECT sum(price)
FROM product;
This statement will returns the total amount for the column price which is 870.
SELECT avg(price)
FROM product;
This statement will returns the average amount for the column price which is 870/4 or
217.50.
SELECT max(price)
FROM product;
This statement will returns the maximum amount for the column price which is 300.
SELECT min(price)
FROM product;
This statement will returns the minimum amount for the column price which is 120.
SELECT count (* )
FROM product;
Group By is used to categorize the retrieved data. For example, you may wight want list
sales of each product identified by product id. To do this, the following is Group By.
example that lists.
Conclusion:
The UNION operator returns only distinct rows that appear in either result, while the
UNION ALL operator returns all rows. The UNION ALL operator does not eliminate
duplicate.
A location_id value that appears multiple times in either or both queries(such as 1700)
is returned only once by the UNION operater, but multiple times by the UNION ALL
operator
INTERSECT Example
The following statement combines the result with the INTERSECT operater, which
returns only those rows returned by both queries:
MINUS Example
The following statement combines results with the MINUS operator, which returns only
rows returned by the frist query but not by the second:
SELECT product_id FROM inventories
MINUS
SELECT product_id FROM order_items;
Conclusion:
Experiment no.: 7 Date:
Theory:
You can combine multiple queries using the set operators UNION, UNION ALL, INTERSECT
and MINUS. ALL set operators have equal precedence. If a SQL statement contains
multiple set operators, than Oracle evaluates them, from the left to right if no parentheses
explicitly specify another order.
The corresponding expressions in the select lists of the component queries of a compound
query must match in number and datatype. If component queries select character data,
then the datatype of the return values are determined as follows:
- If both queries select values of datatype CHAR, then the returned values have datatype
CHAR
- If either or both of the queries select values of datatype VARCHAR2, than the returned
values have datatype VARCHAR2.
UNION Example
The following statement combines the result with the UNION operator, which eliminates
duplicate selected rows. This statement shows that you must match datatype (using the
TO_CHAR function) when columns do not exist in one or the other table:
Theory:
CREATE TABLE branch
(name varchar (10) PRIMARY KEY,
city varchar (20),
director varchar (20),
assets number)
Integrity Constraints
attribute Constraint
CREATE TABLE t1
(
c integer PRIMARY KEY,
d integer NOT NULL,
e integer)
Integrity Constraints
attribute Constraint
CREATE TABLE t1
(
c integer PRIMARY KEY,
d integer NOT NULL UNIQUE,
e integer)
SQL DDL, creation example
CREATE TABLE branch
(name varchar (10) PRIMARY KEY,
city varchar (20),
director
archar (20) NOT NULL UNIQUE,
assetsnumber)
Integrity Constraints
attribute Constraint
CREATE TABLE t1
(
c integer PRIMARY KEY,
d integer NOT NULL UNIQUE,
e integer REFRENCES t0(f)
f must be a primary key of t0
SQL DDL, creation example
CREATE TABLE branch
( branch_name varchar(10),
city
varchar (20),
employee
varchar (20),
REFRENCES staff(name))
Integrity Constraints
attribute Constraint
CREATE TABLE t1
(
c integer PRIMARY KEY,
d integer NOT NULL UNIQUE,
e integer REFRENCES t0(f)
CHEK (e>18))
Conclusion:
Experiment no.: 9 Date:
Theory: ]
Joints
Using SQL Joints, you can retrieved data more than one table or views using the keys
[Primary & foreign] references.
The SELECT statement contains the columns to retrieve and may come from two or more
tables. If the selected column exists both tables, specify the table [table. column]. You
have to specify the tables in the FROM clause and the joint condition is done in the
WHERE clause. In the WHERE clause, you need the table name and dot followed by
column name. The column name in the WHERE clause is the joint column [keys]. AND
& OR also normally used to make multiple joint conditions, There are about four basic
types of joints, Equality Joints, Outer Joints, Staff Joints, & Inequaligy Joints.
Equality Joints
Equality Joints happens when two table are joined based on values in one table being
equal to values in anther table. For example, product table and inventory table may have
joint column of product_id as it show in the following tables.
Product Table
Cost
Product ID Name Description Price
100000000 Printer Inkjet 300 colour Printer 120 80
100000001 Printer 1220XI Inkjet Printer 200 130
100000002 Printer Photo 890 Inkjet Printer 250 200
100000003 Printer Photo 890 Inkjet Printer 300 270
Inventory Table
mx_req
100000000 20 0 10 25
100000001 10 5 2 15
100000002 2 10 1 12
100000003 1 15 1 15
Product table is specified in the SELECT statements to issue the product the product_id
and the reason is, product_id exists both tables and if you dont specified which table to
select from, you will receive ambiguous error. The query will select all the selected rows
from both tables since there is always product_id equal to product_id in the other table.
Outer Joints
Outer Joints is joint condition where all the rows of a table are selected along with then
matching rows in the other table. For example you might want select all your customers
along with their orders if they have orders. + sign is used in the WHERE clause beside the
child table within parentheses. The following is SQL joint statements to select every
customer in the customer table along with their orders if they have orders and if they.
Self Joints
Self Joints is joint of table by it self. For example, if you want retrieve customers whom
ordered same products twice or more assuming there is num_order column that keeps
track the number of orders customers made. Here is how you would do this using a self
joints:
SELECT 01. customer_id
FROM order 01, order 02
WHERE 01. item_id = 02. item_id AND 01.num_order>1;
This query simply created two table alias, 01 and 02 which represents two copies of the
table order then compares if item_id exists both table when order is placed two or more
times by a customer.
Inequaligy Joints
Inequaligy Joints is when each record in one table is joined with every record in the
second table using operators <>, <, >, =, etc. to define an inequality condition. Its
opposite of inner joints. This type of joint is rarely used since joint. This type of joint is
rarely used since joint columns are keys & inequality comparison of the keys has no
meaningful applications.
Conclusion:
Experiment no: 10 Date:
Aim: To Study views and indices.
Indixes:
Indixes in the store database are B+tree structures with a fixed size key. This means that
text keys may easily generate large indexes, and maximum length text column cannot be
indexed.
Keys in DBMS may be truncated by specifying the length of a text column to be used it
the index key. Such a key column must always be the last one in the key, to ensure that
the index provides a true ordering. If a text key column does not supply a truncation
length, the full length of the table column is used.
Apart from Binary and LongBinary columns, all types can be used in an index key
including LongText8 and LongText 16, although these must supply a truncation length
(as they have no maximum length) and must therefore be the last key columns in the key.
VIEWS
SQL View is a virtual or temporary table. Sql view is similar to the query in access so
that you retrieve data from a table and store it in a view. Views are often created because
of security reasons or to retrieve and store data from different tables. You can create
because of security reasons or to retrieve and store data from different tables. You can
create a view same way as a table. Select statements is used to retrieve data from a table.
Here is an example of creating a view:
The name of the view we just created is product_view, which selects two columns. Name
and desc from product table. The values from these two columns will be stored in this
view.
Conclusion :-
UNIT VI
Database System Architectures and Distributed Database: Centralized Systems,
Clime/ Server Systems, Parallel Systems, Distributed data storage, Network
transparency Distributed query processing, Distributed transaction model, Commit
Protocols, Concurrency controls, Deadlock handling, Multidatabase Systems.
Text Books :
1. Database System Concepts: Korth, Silbersehatz: Megraw- Hill
2. Database Management System : Majumdar & Bhattacharya
3. Principles of Database : Jeffrey D. Ullman
4. An Introduction To Database Systems : C. J. Data (Adison Wesley - Nerosa