Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Notes-Class-X DBMS (Part-II)

The document provides comprehensive revision notes for Class X Information Technology, focusing on Database Management Systems using Libre Office Base. It covers SQL commands for creating, inserting, updating, and deleting records in tables, as well as sorting data and managing relationships between tables. Additionally, it explains how to retrieve data using queries and the importance of referential integrity in maintaining data accuracy.

Uploaded by

vaanyaraushan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Notes-Class-X DBMS (Part-II)

The document provides comprehensive revision notes for Class X Information Technology, focusing on Database Management Systems using Libre Office Base. It covers SQL commands for creating, inserting, updating, and deleting records in tables, as well as sorting data and managing relationships between tables. Additionally, it explains how to retrieve data using queries and the importance of referential integrity in maintaining data accuracy.

Uploaded by

vaanyaraushan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Indraprastha INTERNATIONAL SCHOOL

Sector 10, Dwarka, New Delhi – 110075

Session: 2024-25
Class X
Information Technology (402)
DATABASE MANAGEMENT SYSTEM
REVISION NOTES

Create table SQL command-


Libre Office Base also supports SQL view to create a table.
Steps:
1. Click on Tool –> SQL command. Execute SQL statement will open.
2. Type the following command to create table and click on Execute:
Syntax-
Create table table_name (Field_name datatype, Field_name datatype,.......);
Example-
create table Students (RNO integer primary key, Sname varchar(20),
DOA date);
Note- ; (semicolon) is mandatory at the end of every SQL Query.

Insert Records in the Table using SQL command-


You can insert data into table using SQL view.
This option requires SQL command to insert a record.
The Insert Into command is used to add records through SQL command.

Step 1 > Click on Tools > SQL.


A new window appears with the title Execute SQL Statement.
Step 2 > Now type following command to insert record.
Syntax-
Insert into table_name (column_list) values (value1, value2, value3, ........);
Example-
insert into dept (dno, dname, loc) values (50,'TPP','Bhuj');
Step 3 >Now click on Execute button. Below in the Status area, you get the message
“Command executed successfully. “.
Step 4 > Click on Close button.
Step 5 > Click View > Refresh Tables option to see the updated table.
You can avoid the column names if you are going to insert all records.
Example:
insert into dept values (60,'Hospital','Township');

Edit Records in the table using SQL command-


You can edit any records using SQL command.
The Update command is used to edit records through SQL command.
Syntax-
UPDATE TABLE table_name SET column_name=value WHERE condition;
Example-
Open Execute SQL statement window. and type the following command:
update dept set deptno=100 where deptno=10;
In the above command –

Delete records from the table


Open the database and table in datasheet view and open the table from which you want to
delete the record.
Delete record in Datasheet view
Place your cursor on the record in the table and do one of the following:
1. Click on Edit > Delete Record option.
It will ask your confirmation to delete selected data with “Yes”/“No” button.
2. Or you can Right-click and select Delete option.
3. Or Select the entire row, do right-click and choose the option Delete Rows and click on
“Yes” button to confirm deletion.

Delete record using SQL view


The Delete command is used to delete records through SQL command.
Syntax-
DELETE FROM table_name WHERE condition;

Open Execute SQL statement window and write the following command:
Delete from dept where deptno=100;

Note: The Delete command without any condition will delete all records from the table.
Delete from dept;
Sorting Data
Sorting rearranges the data in an ascending or descending order.
Sort records in Datasheet view
To sort data in Libre Office Base, follow these steps:
Step 1 > Select the column which you want to sort.
Step 2 > Now click on appropriate button from the toolbar as highlighted below in
screenshot. Your datasheet displays the result accordingly.

Sort records using SQL view


We can sort records using SQL ORDER BY clause in the query.
By default the records are sorted in ascending order. To sort them in descending order, we
can use DESC keyword.
Consider the following example:
select * from emp order by ename;
select * from emp order by ename desc;

Referential Integrity
The primary key and foreign key which are used for referential integrity, link more than one
table with each other. The referential integrity help to maintain the accuracy and consistency
of data in the relational database.

Advantages of referential integrity in database


 Add records into the referenced table even when there are no matching records in the
parent table (Primary Key table)
 Update records automatically when changes made to the parent table
 Delete records automatically from the parent table
 Allows to retrieve linked data as and when required
 Save the time of database developer
 No need to enter the same data in separate tables
 Reduce data entry errors
Types of Relationship
There are three types of relationships:
1. One to One: Each record of one table is related to one record of another table.
2. One to Many or Many to one: Each record of the table is related to one or more than
one records in another table.
3. Many to Many: This type of relationship links or more records with one table to
another table’s one or more records.

Creating and Editing Relationships between Tables


By creating a relationship using Libre Office Base, we are going to provide a connection
or link orassociation between two tables. Hence it avoids data redundancy, in simple
words, data duplicity can be avoided.
Steps to Create a relationship in Libre Office Base
We first need to create tables, to create relationship with primary key and foreign key.
Follow the below given steps to create relationship:
1. Click on Tool > Relationships. A new window appears to add tables in the relationship.
2. If tables are not available, click on Insert > Add Tables option or click on Add
Tables icon on the taskbar.
3. Select the tables.
4. Click on Insert > New Relations.
5. Relations window appears to select the Tables and fields.
6. Select the Primary key field of both the tables, then click on the OK button.
Note: If you want to create a relationship using drag and drop click on the field of the
primary key of one table and link them with the foreign key of the child table.
Remove Relationship
You can remove this relationship using one of the following:
1. Click on connecting line and press delete key.
2. Click on connecting line and do right click, then select Delete option.

Retrieve data using Query


Database Query
Query helps you to perform searching in the database and returning the matching record
from it. It can be run on multiple tables as well. You can filter the results using criteria and
display specific results. Libre Office base provides an option to choose criteria for your
search.
Defining Query
A query is a command of DBMS system that retrieves data from the database table.

Libre Office Base provides three ways to perform a query:


1. Query using wizard
2. Query in design view
3. Query using SQL view

Query creation using the wizard


The steps are as following:
1. Open your database and select Queries from object pane.
2. Click on Use Wizard to Create Query option from the Tasks window.
3. Now Query Wizard will open.
This query wizard has 8 simple steps.
1. Field Selection – This step allows us to select the required fields from the table. Select
the table and click on the required fields, then click on the > button. Click on Next.
2. Sorting Order – You can sort the records using this step. There are four options to sort
the records with different fields. Select the column name and choose the order
Ascending or Descending order. Click on Next.
3. Search Conditions – In this step you are allowed to select specific conditions or criteria
like Match all fields for all records or match any of the following then Select the field and
conditions such as is equal to, is not equal to, is smaller than, is greater than, is
equal or less than, is equal or greater than, like, not like, is null, is not null and enter
the value at the last. Click on Next.
4. Detail or summary – It will show the detail or summary for your query results. Click on
Next.
5. Grouping – If you want to group the records according to certain values this option is
used. By default this option is disabled.
6. Grouping Conditions – If you have applied grouping in step 5, then only this option will
appear.
7. Aliases – This option allows you to choose the alias names from your selected fields.
Type the name in the box and click on Next.
8. Overview – This step displays the overview of your query. You can display the query
result or modify the query. If everything is fine, click on Display query button.
Finally, click on the Finish button to show the result.

Query in Design view


Follow the given steps to perform query in design view:
1. Open your database and select Queries from the object pane window. A new window
appears to add tables for your query.
2. Select the table and click on Add Tables option.
3. Now in the Fields row at the bottom and choose whatever field you need to display in
the query results.
4. If you want to use any alias for your fields type name exact below the field name.
5. After then move down to the next row to sort your records. Just select go to the row
where you want to sort the records and select it.
6. Next is function, whenever you want to perform calculation or want to use some
functions you can select this option.
7. Next row is Criterion, which is very important to display the records according to the
criteria. Here you can use the comparison operators like >, <, >=, <=, = or != etc.
8. Then number of criteria you can add as per the requirements.
9. Now finally save your query and view the results.

Create Query in SQL View


SELECT command is a type of DML command that allows displaying records from a table.
Syntax:
Select */columns_list from table_name where condition;
There are four ways you can use Select query:
1. All records
2. All records with limited columns
3. Limited records with all columns
4. Limited records with limited columns
All records
Whenever you want to fetch all records from table you can use this option.
Example:
select * from emp;

All records with limited columns


Whenever you want to fetch all records with limited columns from table use specific column
names with select clause.
Example:
select empcode, ename, job from emp;

Limited records with all columns


Whenever you want to access all columns * is used after select clause and
To limit records,WHERE condition is used. With where condition some Relational
Operators are used as per the requirement. These operators are:
1. < : Display the records less than the specified column value.
2. > : Display the records more than the specified column value.
3. <= : Display the records less than or equal to the specified column value.
4. >= : Display the records greater than or equal to a specified column value.
5. = : Display the records equal to a specified column value
6. <> : Display the records no equal to the specified column value.

Like Operator : This operator is used to pattern matching criteria like the character is
starting with,ends with or have a specific position in the value. The ‘%’ is used to specified
any number of character whereas ‘_’ is used to specify the position of characters.
For example, you want to search a record whose fourth letter of name is ‘i’ and last
character is ‘T’, then the query will be written as –

Select * from emp where ENAME like ‟_ _ _ _I%T‟;

Not Like Operator : Display all the records except the specified pattern matching
Is Null Operator : Display records with null values
Is Not Null Operator : Display records except null

Limited records with limited columns


Specify the column names after select and use where condition to restrict them.
select empno, ename from emp where ename='MOHIT';
Examples:
select * from emp where empno<1020;
select * from Emp where empno>1015;
select * from Emp where job<>’Manager’;
select * from Emp where ename like ‘M%T’;
select * from Emp where ename is null;
select * from Emp where ename is not null;

Grouping Records
We can group the records based on the values of a specified column using GROUP BY
clause in the query.

Example:
select job, count(job) from emp group by job;

You might also like