Ln. 3 - Relational Database Management System Grade 10 CBSE
Ln. 3 - Relational Database Management System Grade 10 CBSE
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.
• 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.
• Organised Storage – The data is stored in an organised manner, so that retrieval of the
required data is fast and accurate.
• Data Analysis – A database helps in analysis of data based on certain criteria.
• Data Consistency – By minimising data redundancy, chances of inconsistent data being
stored is reduced.
• Increases Efficiency and Accuracy –Data is retrieved accurately from the database.
• Security – Unauthorised access can be controlled by assigning passwords to the users.
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.
Data Models
A database can be designed in different ways depending on the data being stored.
Data models are used to describe how the data is stored, accessed, and updated in a DBMS.
3 types- hierarchical data model, network data model, relational data model.
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.
• 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. This foreign key helps to build a
relation between two tables.
✓ Candidate Key – All the field values that are eligible to be the primary key are the candidate
keys for that table. Such fields can neither be left blank nor can have duplicate values.
✓ Alternate Key – Out of the candidate keys, one or two are made as primary keys. The others
are the alternate keys. Hence, if Roll Number is made as the primary key, Admission Number
is the Alternate key.
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
Note-
✓ The database in Base is saved with an extension .odb.
✓ Also note that if no name is given to the database, then it is saved with a default name as
NewDatabse.odb.
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:
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).
LibreOffice Base gives us 4 options to choose from to maintain referential integrity. (Rt. Click
the relationship line)
• No action – This is the default option. This option states that a user should not be
allowed to update or delete any record in the master table if any related record exists in
the transaction table.
• Update cascade – This option allows the user to delete or update the referenced field but
along with it all the related records in any of the transaction tables will also be deleted or
updated.
• Set NULL – This option assigns NULL value to all the related fields if the master record is
deleted or updated.
• Set default – This option assigns any fixed default value to all the related fields if the
master record is deleted or updated.
Data Types-
The Data types used by SQL are-
✓ Numeric - int, integer, float
✓ Text - char , varchar
✓ Date - Date
Categories of SQL-
There are two types of categories :-
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.
• To retrieve all the columns in a table the syntax is:
SELECT * FROM <TABLENAME>;
Eg:- select * from emp;
Here * represents all the details.
Select age, name from emp;
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’;
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;
• 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”
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;
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.
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.
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
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
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
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:
EMPNAME Varchar(15)
Design Varchar(20)
Salary Decimal