Comprehensive Database Management System Class 10 Notes IT 402
Comprehensive Database Management System Class 10 Notes IT 402
IT-402
Database Management System
What is Database?
An organised group of data that is kept and accessible electronically is referred to
as a database. It is a digital repository that enables the effective management, storage,
and retrieval of both organised and unorganised data. Information like client records,
financial data, inventory listings, and much more can be stored in databases. Example of
database are – Microsoft Access, OpenOffice Base, Oracle, MySQL and
PostgreSQL etc.
Data types in OpenOffice base are broadly classified into five categories listed
below.
• Numeric Types
• Alphanumeric Types
• Binary Types
• Date time
• Other Variable types
Numeric Types
Numerical data types are data types that store numeric values in a database. Numeric
data types can be further divided into several subtypes, including:
Alphanumeric Types
Data that has both letters and numbers is referred to as alphanumeric type.
Binary Types
For storing data in binary formats, binary data types are utilised. In a database, binary
data types can be used to store things like music and image files. The binary data type
can generally be used to store files in any format.
Date Time
When specifying date and time values for a column used in a database table, date time
data types are used. Information like dates of birth, admissions, product sales, and other
dates can be stored in databases using date and time data types.
Select the table > Right click > Select the option Edit > the table Design View
window will open
Following are some properties of data of the numeric type:
1. AutoValue – if set to yes then field will get the auto numeric values.
2. Length – By default length of the field is 10 but the size of the field can be set
to maximum length.
3. 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.
4. Format example – This property helps to set the format of the data entered in
the field such as 91-222-333.
Following are some properties of data of the character type:
1. 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.
2. Length – By default length of the field is 10 but the size of the field can be set
to maximum length.
3. 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.
4. 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. Sorting
is the process of putting data into a meaningful order so you can evaluate it more
efficiently.
Referential Integrity
The relationship between tables is referred to as 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:
1. Adding records to a related table if there is no associated record available in
the primary key table.
2. Changing values in a primary if any dependent records are present in
associated table(s).
3. 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
An association or link between two or more tables is referred to as a relationship. You
don’t have to enter the same data again in different tables when you relate two tables.
1. ONE to ONE
2. ONE to MANY OR MANY to ONE
3. MANY to MANY
ONE to ONE
In this relationship, both the tables must have primary key columns.
ONE to MANY OR MANY to ONE
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
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.
Note Removing the Relationships – With the use of the Delete option, the relationships
that have been applied to the tables can also be deleted. When you right-click a
relationship thread, the Delete option will appear.
Session 4 : Retrieve Data using Query
In order to describe the data structure and to modify the data in the database, queries
are used as instructions. A query enables the joining and filtering of data from various
tables.
Database Languages having two type:
1. DDL (Data Definition Language)
2. DML (Data Manipulation Language)
DDL Statements:
• Create: Using this statement, a database or set of tables can be created.
• Alternate: This statement is used to change the table’s structure.
• Drop: This statement is used to remove database objects from the system.
DML statements:
• SELECT: The statement “SELECT” is used to get data from the database.
• INSERT: The statement “INSERT” is used to add a new record to the
database.
• DELETE: The database can be cleaned out by using the statement DELETE.
• UPDATE: This statement is used to modify the database’s information.
Database Query
Query is a computer languages. In order to describe the data structure and to modify the
data in the database, queries are used as instructions. Query can extract particular data
from a database. We can filter and join data from various tables with the help of a query.
By using the criteria you supply query will filter the data.
Select Statement
A select query is a language in a database that displays data in Datasheet view. Data
from tables is displayed by a query rather than being stored by it. A query may display
data from one or more tables, from other queries, or from both of these sources
simultaneously.
The SELECT statement has many optional clauses:
• WHERE specifies which rows to retrieve.
• ORDER BY specifies an order in which to return the rows.
Syntax of Select Statement is –
SELECT * FROM <TABLENAME>;
Query related to Simple Select Statement –
Table Name – product
Product_No Product_Name Price Quantity
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
Soap
Powder
Shampoo
Soap Box
Question – Write a Query to display Product_Name and Price from the table;
Select Product_Name, Price from product;
Output –
Product_Name Price
Soap 40
Powder 80
Shampoo 300
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
25 Soap 3200
31 Powder 2400
45 Shampoo 6250
Question – Write a query to find the average price of the total product;
Select avg(Quantity) from product;
Output – 58.75
Query related to Select Statement with Where clause
Table Name – product
Product_No Product_Name Price Quantity
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
Question – Write a Query to display the product whose price is less than 90
Select * from product where price < 90;
Output –
Product_No Product_Nam Price Quantity
25 Soap 40 80
31 Powder 80 30
Question – Write a Query to find the total amount of the Shampoo product;
Select Price*Quantity from product where Product_Name = ‘Shampoo’;
Output – 6250
Or
Select Product_No, Product_Name, Price*Quantity from product where Product_Name
= 'Shampoo';
Output – Product_No Product_Nam Price*Quantity
45 Shampoo 6250
Question – Write a Query to display the data whose quantity is equal to 80.
Select * from product where quantity = 80;
Output –
Product_No Product_Nam Price Quantity
25 Soap 40 80
25 Soap 40 80
31 Powder 80 30
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
31 Powder 80 30
45 Shampoo 250 25
25 Soap 40 80
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
45 Shampoo 250 25
31 Powder 80 30
25 Soap 40 80
UPDATE_statement
To edit or update already-existing records in a table, use the UPDATE statement. Using
the WHERE clause, you can either define a specific subset of entries to edit or use it to
update everything at once.
Syntax of Update Statement –
UPDATE <table name> SET = value [, column_name = value ...] [WHERE ];
Table Name – product
Product_No Product_Name Price Quantity
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
Question – Write a Query to update the price of Shampoo in the product table.
Update product Set Price = 300 where Price = 250;
Output –
Product_No Product_Name Price Quantity
25 Soap 40 80
31 Powder 80 30
45 Shampoo 300 25
25 Soap 40 80
31 Powder 80 50
45 Shampoo 250 25
Create Table
To create a new table in the database you can use Create Table Command.
Syntax of Create Table –
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype);
Question – Write a Query to create the following table in the database;
Table Name – product
Field DataType
Product_No Integer
Product_Name Varchar(20)
Price Integer
Quantity Integer
Insert Table
Insert statement is primarily used to add a single or more rows to the target table.
Syntax of Insert Table –
INSERT INTO table_name (column1, column2, column3, ...) VALUES
(value1, value2, value3, ...);
Or
INSERT INTO table_name VALUES (value1, value2, value3, ...);
Table Name – product
Product_No Product_Name Price Quantity
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
25 Soap 40 80
31 Powder 80 30
45 Shampoo 300 25