Professional Documents
Culture Documents
Ln. 3 - Relational Database Management System
Ln. 3 - Relational Database Management System
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
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.
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).
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.
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>;
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’;
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;
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