Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

UNIT-3 RELATIONAL DATABASE MANAGEMENT SYSTEMS

SESSION 1: APPRECIATE THE CONCEPT OF DATABASE MANAGEMENT SYSTEM


SESSION 2: CREATE AND EDIT TABLES USING WIZARD AND SQL COMMANDS
SESSION 3: PERFORM OPERATIONS ON TABLE
SESSION 4: RETRIEVE DATA USING QUERY
SESSION 5: CREATE FORMS AND REPORTS USING WIZARD
SESSION 1: APPRECIATE CONCEPT OF DATABASE MANAGEMENT SYSTEM
Data vs information -
• Data is raw facts or observations.
• Processed data is called information.
Database -
• A database is a well-organized collection of interrelated data.
• You can visualize it as a container of information.
Database Management System (DBMS)-
 A DBMS is a software that can be used to create and manage databases.
 It lets users to create a database, store, manage, modify and retrieve data from that
database by users or application programs.
 A DBMS allows different user application programs to concurrently access the same
database.
 Examples of popular DBMSs are : MySQL, Microsoft Access, Oracle, DB2 and Sybase.

Types of data files


Data can be organized into two types:
• Flat File: Data is stored in a single table. Usually suitable for less amount of data.
• Relational: Data is stored in multiple tables and the tables are linked using a common field.
Relational is suitable for medium to large amount of data.
Database servers
• A database server is a computer system that provides other computers with services related
to accessing and retrieving data from a database.
• Access to the database server may occur through a "front end" running locally a user's
machine or "back end" running on the database server itself.
• Such type of data access is referred to as a client-server model.
Advantages of databases
• Reduces Data Redundancy (Duplication of data is reduced)- Data redundancy occurs when
the same piece of data exists in multiple places. This is prevented in a database as there is a
single database and any change in it is reflected immediately.
• Sharing of Data - The data can only be shared with the authorized users.
• Data Integrity - Data integrity means that the data is accurate and consistent in the
database.
• Data Security
• Privacy
• Backup and Recovery - The users don't need to backup data periodically because this is
taken care of automatically by the DBMS. Moreover, it also restores the database after a
crash or system failure to its previous condition.

Database Concepts
Database contains objects that are used for storing and managing information.
1. Item : – Item is about which information is stored in the database.
2. Field:- Each question that we ask about our item is a Field.
3. Record:- Record is a set of information (made up of fields) stored in your database about one
of the items.
4. Value:- Value is the actual text or numerical amount or date that you put in while adding
information to your database.

Database Features
• A database can have one or many tables.
• Each table in a database contains information about
one type of item.
• Record should be unique in every table.
• Every database table should have one or more fields
designated as key.
✓ Collection of related data → field
✓ Collection of related fields→ record
✓ Collection of related records→ table
✓ Collection of related tables→ database

RDBMS
• Once the tables have been set up, a relationship can be created to link them together.
• Such a database that stores data in separate tables that are related through the use of a
common column is called a Relational database.
• It is based on the relational model as introduced by E. F. Codd.
• A DBMS used to manage Relational Databases is called an RDBMS (Relational Data Base
Management System).
• Some popular RDBMS software available are: Oracle, MySQL, Sybase, Ingress

Keys
In the RDBMS data can be integrated using keys. These are Primary Key, Composite Primary
Key, and Foreign Key.
Primary Key:
• A primary key is a field in a table that is unique for each record.
• It does not have duplicate values or null values.
• It can be a combination of more than one field.
• There can be only 1 primary key in a table
Composite Primary key:
A primary key that is made by the combination of more than one attribute is known as a
composite key.
Foreign key:
It identifies a column or set of columns in one (referencing) table that refers to a column or set
of columns in another (referenced) table.

SESSION 2: CREATE AND EDIT TABLES USING WIZARD AND SQL COMMANDS
Components of a DB package-
1. Tables 3. Forms
2. Queries 4. Reports
Query – Basic tool to retrieve information. It helps to filter large set of data based on the given
criteria.
Forms- An interface that lets the user to enter or view data.
Report- Displays information in a format as per the user needs. Used to view and print report.

Tables-
• In a relational data model, the data is organized in the form of tables.
• A table is a 2 dimensional representation of data using rows & columns.
Rows or Records or Tuples:
• The horizontal subset of the Table is known as a Row/Tuple/Record. Each row represents
a record, which is a collection of data about a particular person, place or thing.
Columns or Fields or Attributes:
• The vertical subset of the Table is known as a Column/Attribute / field. Each column has
a unique name and the content within it must be of the same type.

DATA TYPES
• Datatypes are used to identify the type of data we are going to store in the database.
• Data types can be broadly classified into five categories:-
1. Numeric Types 2. Alphanumeric Types 3. Binary Types
4. Date Time 5. Other variable Types

NUMERIC DATA TYPES


Numeric data types are used to describe numeric values for the field used in the table of a
database.
Can be used for storing information such as mobile number, roll number, etc.

ALPHANUMERIC DATA TYPES


BINARY DATA TYPES
Binary data types are used for storing data in binary formats.
Binary data types in a database can be using for storing photos, music files, etc.
In general, files of any format can be stored using the binary data type.

DATE TIME DATA TYPES


Date time data types are
used for describing date and
time values for the field used
in the table of a database.
Date time data types in a
database can be used for
storing information such as date of birth, date of admission, date of product sale, etc.
OTHER DATA TYPES

CREATING DATABASE USING OPENOFFICE

Open Office → Open Office Base


Steps To Create A Table Using Table Wizard
• Tables are the basic building blocks of a database.
• You store the data in the database in the form of tables. There are different ways to create a
table:
1. Create table in Design View
2. Use Wizard to Create Table

CREATING TABLES IN DESIGN VIEW


Click on Tables > Use Wizard to Create Table , the window shown below will open

Click the Select Fields > Choose Category > Select the table (in the picture shown below
“Business” category and “Customer” table has been chosen) > Click on Next Button.
Select the fields as per the
requirements and select on buttons to
add the predefined columns or select
to remove the fields from the Selected
Fields Box. Click on Next Button.
Next the window to set the data types
will open. By default all the fields will
have Text[VARCHAR] data type which
can be and other properties with
default values but all of them can be
selected as per the requirement. Click
on Next Button.

After setting the properties of the fields such as field name, type etc. The window to set the
primary will open. Base automatically adds the column to be set as Primary Key which will help
the user to enter the unique values and helps in creating the relationship with the other table to
extract the data from multiple tables. After setting the Primary Key click on Next Button.

Next, give a name for the table. The option to insert


the data immediately will be selected by default . Click
on Finish to insert the data in the table.

To insert the data the following window open:


Creating table using Design View
1. Click on Create Table in Design View… option available under
Tasks and a Table Design window appears as shown below.
• Specify the field name and data type of the field to be
created by selecting the appropriate type available under
Field type dropdown list.
• For example, the table contains the Name field and the data
type of the Name is TEXT [VARCHAR]. You can specify the
length of the field value.
• After giving the field names and data types, save the table.

Options to set Primary Key


• You are asked to set a primary key for the table you just created. You can select the
appropriate option to set the primary key or leave the table without a primary key.
• If you click Yes, the application will set the primary key for the first field created
automatically. If you click No, you should see a window similar to the one displayed below.

SESSION 3 : PERFORM OPERATIONS ON TABLE


Inserting data in tables
• Data is stored in tables that can be
inserted, modified & removed
using appropriate options.
• Select the table > Double click on
it.
• The table will open in Datasheet View in which data new data can be inserted and existing
data can be updated or removed.

Editing data in tables


• Data is stored in tables which can be inserted, modified and removed using appropriate
options.
• Select the table > Double click on it.
• The table will open in Datasheet View in which data new data can be inserted and
existing data can be updated or removed.
Deleting Records From The Table
• Select the data > right click on selected data > select the Delete option

Field Properties
• In design view there are properties of fields according to the data type set for each field.
• The properties of numeric type data -
✓ Like AutoValue – if set to yes then field will get the auto numeric values.
✓ Length – By default length of field is 10 but size of the field can be set to maximum length.
✓ Default Value – A default value can be set for a field if user don’t provide any value while
entering the values in the table.
✓ Format example – This property helps to set format of the data entered in the field such as
91-222-333.
• Character type data properties -
✓ Entry Required – if set to yes then it will be must to insert the value in the field which means
that field cannot be left blank.
✓ Length – By default length of field is 10 but size of the field can be set to maximum length.
✓ Default Value – A default value can be set for a field if user don’t provide any value while
entering the values in the table.
✓ Format example – This property helps to set the format of the data entered in the field such
as 91-222-333.

Sorting Data
• Sorting means to arrange the data in either ascending order of descending order.
• Select the column(s) then click on sort buttons.
• The data will be displayed accordingly.
Unsorted Column (EMP_NAME) Sorted Column (EMP_NAME)
Referential integrity
• Referential integrity is used to maintain accuracy and consistency of data in a relationship.
• In Base, data can be linked between two or more tables with the help of primary key and
foreign key constraints.
• Referential integrity helps to avoid:
✓ Adding records to a related table if there is no associated record available in the primary key
table.
✓ Changing values in a primary if any dependent records are present in associated table(s).
✓ Deleting records from a primary key table if there are any matching related records available
in associated table(s).

Creating and Editing Relationships between Tables


• A relationship refers to an association or connection between two or more tables.
• When you relate two tables, you don't need to enter the same data in separate tables.
• Tools → Relationships
• You can create a relationship between any two tables by selecting Relationships… option
from the Tools menu.
Relationships between tables helps to:
• Save time as there is no need to enter the same data in separate tables.
• Reduce data-entry errors.
• Summarize data from related tables.
Add the tables in amongst which you want to create the relationship. Select the tables and click
on Add button.

There are two ways to create the relationships between the tables:
a. Click on Insert option and select New Relation… option in Relation Design window. Select
the options as required.
b. Drag the primary key column from one table and drop it on the key column of another table.
There are three types of relationships which can be created in tables:
1. ONE to ONE
2. ONE to MANY OR MANY to ONE
3. MANY to MANY
One to One Relationship
• In this relationship, both the tables must have primary key columns.
One to Many Relationship
• In this relationship, one of the table must have primary key column.
• It signifies that one column of primary key table is associated with all the columns of
associated table.
Many to Many Relationship
• In this relationship, no table has the primary key column.
• It signifies that all the columns of primary key table are associated with all the columns
of associated table.

Remove the Relationships


The relationships applied on the tables can be removed also with the help of Delete option.
Right Click on the relationship thread and select Delete option.

SESSION 4: RETRIEVE DATA USING QUERY


• To extract information from a table we have to query the database.
• A query is to collect specific information from the pool of data.
• It helps us join information from different tables and filter that information.
• Filtering means that the query uses criteria you provide to hide some data and present only
what you want to see.

Query Creation Using Wizard

• Select Query from Database components.


• Choose ‘Use Wizard to create Query’ option
• Choose the sorting order
• Select the search conditions and then the types of query
• Click on Finish

Query Creation in SQL view


• Query languages are computer languages used to make queries into databases and
information systems.
• SQL - Structured Query Language is a query language that lets to access and manipulate
databases.

There are two types of languages:-


1. DDL (Data Definition Language)
2. DML (Data Manipulation Language)

DATA DEFINITION / DESCRIPTION LANGUAGE:- It is a standard for commands that define the
different structures in a database. DDL statements create, modify and remove database objects
such as tables, indexes and users.
Common DDL Statements are:-
1. Create :- Used to create database objects.
2. Alter :- Used to modify database objects.
3. Drop :- Used to delete database objects.

DATA MANIPULATION LANGUAGE:- It is a standard for commands that enables users to access
and manipulate data in a database.
Common DML Statements are:-
1. SELECT :- Used for retrieval of information from the database.
2. INSERT :- Used for insertion of new information into the database.
3. DELETE :- Used for deletion of information in the database.
4. UPDATE :- Used for modification of information in the database.

CREATE Statement
Create statement is used for creating a database or a table. The general syntax is-
CREATE TABLE <TABLENAME> ([column name] [data type])
Eg:-
CREATE TABLE Employee (ID INTEGER, Name VARCHAR (50), Department VARCHAR (50),
Address VARCHAR (120), Contact_Number INTEGER);

Remove a table-
Drop table Stud;
To add a new row to the table-
INSERT statement is used to add one or more records to a database. The general syntax is –
INSERT INTO <table_name><column1, column2,…> VALUES <value1, value2, value3 …>;
insert into stud values (1, ‘Ajay’, 16,10);
insert into stud values (2, ‘Vivek’, 15,10);
Note-
Character, date and time should be enclosed in quotes.
Numeric values should not be enclosed in quotes.
SELECT statement-
• A SELECT statement retrieves zero or more rows from one or more database tables or
database views.
• The SELECT statement has many optional clauses:
❑ • WHERE specifies which rows to retrieve.
❑ • ORDER BY specifies an order in which to return the rows.
• To retrieve all the columns in a table the syntax is:
SELECT * FROM <TABLENAME>;

Change the structure of a table –


✓ Alter table command is used to Add, remove or modify columns in a table.
✓ To add a new column :
ALTER TABLE Stud ADD Games VARCHAR(20);
✓ To change the structure of a column:
ALTER TABLE Stud MODIFY games INTEGER;
✓ To delete a column:
ALTER TABLE Stud DROP Games;

Eliminating Duplicate values


▪ The keyword DISTINCT is used to eliminate the duplicate values in the result.
▪ Select DISTINCT Class from Stud;

Arithmetic Operators
▪ Arithmetic operators are + - * /
▪ It is used to perform mathematical calculations.
▪ Select 7 + 76;
▪ SELECT Age+5 FROM Stud;

WHERE clause
▪ To display the records containing the same type of values “WHERE” clause can be used.
▪ It is used to filter records.
▪ It extracts only those records that fulfill a certain condition.
▪ Select * from stud where Class>10;
▪ Select * from stud where Names=’Ajay’;

Condition based on Range [ Between ]


▪ select names from stud where Age between 16 and 17;
▪ Both the minimum and maximum range values will be included in the output.
Condition based on a List [ IN ]
▪ If a list of values are specified, the IN operator is used to select a value that matches any
value in the list.
▪ select * from stud where age IN (15,17 );
▪ select * from stud where Names IN (‘Paul‘,’Firoz’,’Binoy’ );

UPDATE STATEMENT
▪ It is used to modify the existing data in the table.
UPDATE stud SET Class = 12 WHERE names = “Paul”;
DELETE STATEMENT
▪ Used to DELETE one or more rows from a table.
▪ It removes the entire row.
▪ Delete from stud where Sno=6;
▪ To remove all the rows of the table use,
DELETE from stud;
SORTING THE RESULTS- ORDER BY
• ORDER BY is used to display the results of the select statement in ascending or
descending values.
• Select * from stud order by age;
• To display in descending order:
Select * from stud order by age desc;

In order to execute queries click on the Queries option available on the left side under database
section, click Create Query in SQL View as shown below.

• You can type the query in the above window and execute it by using the F5 function key or
by clicking the icon in the window.
• For example, if you want to display all the data in the table that you created in the early
session, then the select statement will be:
Select * from SDetails;
After executing the select query the output will be shown similar to the one displayed below.

Performing calculations
In Base, simple calculations can be done on the data using arithmetic operators.
Example: To display the salary of all the employees after incrementing by 1000 then the
following SQL command will be executed in Base SQL Design.
Select “EmployeeID”, “FirstName”, “Salary” +1000 from “Employee”
• To display the salary of all the employees after decreasing by 10000,
Select “EmployeeID”, “FirstName”, “Salary” - 10000 from “Employee”
• To display the salary of all the employees after incrementing it as twice the amount of
present salary,
Select “EmployeeID”, “FirstName”, “Salary” * 2 from “Employee”

Grouping of Data
To display the records containing the same type of values “WHERE” clause can be used with the
Select SQL Command.
To get details about the list of students whose favorite color is blue, you can use:
select * from SDetails where Color=’Blue’;
To view records in ascending order of RollNo, from the table the select statement will be:
select * from SDetails order by “Rollno” ASC;
To view it in descending order ,
select * from SDetails order by “Rollno” desc;

SESSION 5: CREATE FORMS AND REPORTS USING WIZARD


Form
• A form is an interface in a user specified layout that lets users to view, enter, and change
data directly in database objects such as tables.
Creating Form Using Wizard
• To create a form, Click on Forms option located under Database section.
• Click Use Wizard to Create Form… option under Tasks group.
• You can select selective fields to be sent onto the form by selecting the field name and
clicking >button. You can select individual fields in a database or all fields in a database.
• To use all the fields in the table in a form, click the >> button.
• Click Next >. Now you need to arrange selected fields in a form. You can use different styles
from the list.
• Once you have selected a style, click Next. A
dialog box appears wherein you can select the
data entry model.
• Click Next >. You should see a dialog box
wherein you can specify the styles to be used
in the form.

Click Next >. You see a dialog box where you can
specify the name of the form. Click Finish.
A form window appears. Notice that the records in the
table are displayed automatically within the form that
you just created.

Options To Enter Data From Forms


You can add new records to the table using the form by
clicking the symbol located at the bottom.
Once you click the symbol, you will be displayed with a
window for creating records.

Report
• A report helps to display the data in a summarized manner.
• It is used to generate the overall work outcome in a clear format.
• To create reports in Base, the table must be selected from using which data can be displayed
in a format as required.

Creating Reports using wizard


The steps to create followed are :
• Click on Reports section under Database in the OpenOffice base application.
• Click on Use Wizard to Create Report… option available under Tasks.
• Select all the table fields by selecting the >> button, once you click the button >> you
should see a dialog box similar to the one displayed below.
• Define grouping for the fields of the table.
• Once you click Next >, you can sort the field variables in the report by selecting the
appropriate field and sorting method.
• Once you click Next >, you should see a dialog box similar to the one displayed below.
• Select the layout of the report by selecting the appropriate option available under the
Layout of data down list and you can also select the orientation of the report.
• Give a name for the report or you can use the name of the table itself for the report also.
• Click Finish.

Fill in the blanks


1. A table is a primary database object that allows searchability, organization and reporting.
2. A column / field is a set of data values of a particular type.
3. A row represents a single data item in a table.
4. When you open OO base, it will start with database wizard.
5. The extension of OO database file is .odb
6. The Create table command is used to create a table using SQL command.
7. To open SQL command, click on Tools -> SQL option in OO base.
8. The keywords are displayed with blue color in SQL command window in OO Base.
9. To run the SQL command, click on execute button.
10. User must type table names and column names in double quotes in SQL command.
11. Some raw facts, figures and textual contents known as data.
12. The meaningful data is known as information.
13. The Database Servers are dedicated computers which holds the actual database and run the
related database software.
14. The database servers database can be accessed through command lines of interface is
known as Front End.
15. The Data security feature of database give access to only the authorized users.
16. The data available in the form of text, numeric or date in the table is known as value.
17. A primary key is a field or column name that identifies records uniquely.
18. The columns which is referenced by another table column through a primary key is known as
Foreign Key

MCQs
1. The database wizard has ________ number of steps.
a) 2 b) 3 c) 4 d) 5
2. The top most object of the database pane or database window is _______.
a) Queries b) Reports c) Forms d) Tables
3. Which of these OO base part displays the additional information about the selected task?
a) Tasks b) Description c) Objects d) Properties
4. Which of the following column allows to select data type for your column in table design?
a) Field Name b) Field Type c) Description d) Field Properties
5. Which of the following part of table design window allows to restrict the length of values in a
column?
a) Field Name b) Field Type c) Description d) Field properties
6. Which of the following enables us to view data from a table based on a specific criterion
a) Form b) Macro c)Query d) Report
7. The table wizard create a table in _______ steps.
a) 1 b) 2 c) 3 d) 4
8. The > sign button in table wizard allows to
a) select a field for a table b) select all fields for a table
c) remove the selected field d) remove all the selected fields
9. Which of the following is a valid SQL type?
a) Character b) Numeric c) Float d) all of these
10. To select multiple fields for a table using table wizard in a one click, which of the following
button is useful?
a) > b) << c) >> d) <
11. In a database Table, the each category of information Is called __________
a) Tuple b) Field c) Record d) all of above
12. Which option is to be chosen to create a connection between two or more tables?
a) Table b) Form c) Relationships d) Sorting
13. Which of the following option is not available in the final step i.e. Create Table through table
wizard?
a) insert data immediately b) Modify the table design
c) create report d) create a form based on this table
14. Which of the following refers to reducing the duplicate values in a table?
a) Data Redundancy b) Data Integrity c) Data Security d) Data Consistency

True or False -
1. The horizontal set of values are known as a field. - False
2. You cannot set the primary key in the table design window. - False
3. The << button allows to remove all the fields in a single click. - True
4. You cannot change the field type once you selected field from table wizard. - False
5. You cannot set the auto value to your primary key field. - False
6. You can modify the table design through table wizard. - True
7. It is mandatory to type SQL commands in capital letters in OO base. – False

Short answer questions – 2 Marks


1. What do you mean by SQL? Explain in short.
2. How to start open office base?
3. Enlist the main parts of OO base window.
4. The database wizard consists of how many steps? Enlist them.
• Select database
• Save and Proceed
5. What are the three options that are available in the select database step of the database
wizard?
• Create a new database
• Open an existing database
• Connect to an existing database

6. What are the steps involved in the table wizard to create a table?
• Select Fields
• Set type and formats
• Set primary key
• Create table

7. Features of Primary key


• It identifies the rows uniquely
• It cannot be null
• It cannot have a duplicate value
• There can only one primary key

8. Give the difference between Flat and Relational database.


Ans: A flat-file database is a database of just one table. It can be created in database software
or in a spreadsheet and is often saved as a CSV file. In relational database store data in multiple
tables .

9. Table – student
S_id Char(5)
Name Varchar(20)
Age Int
Class int
i) Write a query to create the table.
ii) Which field among this can be taken as the primary key?
Ans.
i) Create table “student” ( “S_id” char(5) , “Name” Varchar(20), “Age” integer , “Class” integer)
ii) Primary key – S_id

10. Consider the table below and answer-


TABLE - LIBRARY
Book_id Name Price
100 Harry Potter 50
101 Famous Five 35

i. Specify the data type used for the above table fields (2mrs for the relevant data type)
ii. Add a new record with the following data (2mrs for the correct query)
(‘102, ‘Nancy Drew, ‘40’)
Ans. i) Book_id - Integer
Name – Varchar(20)
Price – Integer
ii) Insert into library values (‘102, ‘Nancy Drew, ‘40’);
11. Write SQL command to create the following tables:

EMPID Char(4) Primary Key

EMPNAME Varchar(15)

Design Varchar(20)

Salary Decimal

Ans. create table "Employee"


("EMPID" char(4), "EMPNAME" varchar(15), "DESIGN" varchar(20), "SALARY" decimal(5,2))

How data is organized in a RDBMS ?


Ans :- In RDBMS, data is organized in the form of inter linked tables.

You might also like