0% found this document useful (0 votes)
35 views7 pages

CH 11 Imp

GSEB Chapter 9 IMP std 11 Computer Subject

Uploaded by

Frank Martin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views7 pages

CH 11 Imp

GSEB Chapter 9 IMP std 11 Computer Subject

Uploaded by

Frank Martin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Chapter : 11

QS- 1 What Are Queries in Base? [5 or 10 marks]

In a database system like LibreOffice Base, queries are tools used to retrieve, update, and manipulate
data stored in tables. Queries allow users to perform specific opera ons on data, such as filtering,
sor ng, aggrega ng, or joining data from mul ple tables, without altering the underlying database
structure.

Types of Queries in Base

1. Select Queries:

o Retrieve specific data from one or more tables.

o Example: Display all students with grades above 80%.

2. Ac on Queries:

o Modify data, such as adding, upda ng, or dele ng records.

o Types include:

 Update Query: Change exis ng data.

 Delete Query: Remove specific records.

 Append Query: Add new records to a table.

3. Parameter Queries:

o Prompt users for input before execu ng.

o Example: Ask the user to enter a city name to filter customers by city.

4. Aggregate Queries:

o Perform calcula ons on data, such as sums, averages, or counts.

o Example: Calculate the total sales for each month.

5. Join Queries:

o Combine data from two or more related tables.

o Example: Show order details along with customer names.

Why Do We Design Queries?

Queries are essen al for working with databases efficiently and effec vely. They are designed for the
following reasons:

1. Data Retrieval

 Purpose: Extract relevant data from large datasets.


 Example: Fetch a list of employees earning more than $50,000.

2. Filtering and Sor ng

 Purpose: Narrow down data to meet specific criteria or organize it logically.

 Example: Filter products by category and sort them by price.

3. Data Analysis

 Purpose: Summarize data for insights and decision-making.

 Example: Calculate the average revenue generated per region.

4. Combining Data

 Purpose: Merge informa on from related tables for a unified view.

 Example: Link Orders and Customers tables to show customer details for each order.

5. Data Valida on and Upda ng

 Purpose: Validate or modify exis ng data efficiently.

 Example: Update all employee records to reflect a new department name.

6. Dynamic Interac on

 Purpose: Enable user interac on through parameterized queries.

 Example: Allow users to search for customers based on dynamic input like city or name.

7. Simplifying Complex Opera ons

 Purpose: Perform complex calcula ons or transforma ons on data.

 Example: Generate a query that calculates the total profit for each product category.

8. Enhancing Applica on Usability

 Purpose: Provide back-end func onality for forms and reports.

 Example: Use a query to feed data into a report summarizing monthly sales trends.

Conclusion

Queries in Base are powerful tools that allow users to interact with, analyze, and manipulate data
stored in a database. They are designed to simplify complex tasks, provide insights, and make data-
driven decision-making more efficient. Whether you're retrieving specific informa on, upda ng
records, or summarizing data, queries are indispensable for effec ve database management.
QS- 2 Use of Criterion in a Query [5 or 10 marks]

A criterion in a query refers to the specific condi on or rule used to filter and retrieve only the
desired records from a database. By applying criteria, you can narrow down the data to focus on
relevant informa on that meets the given requirements.

Purpose of Criteria in Queries

1. Filter Data
Criteria help reduce large datasets by selec ng only the records that match specified
condi ons.

o Example: Retrieve all employees with a salary greater than $50,000.

2. Enhance Query Efficiency


By retrieving only the required data, criteria reduce the amount of data processed and
displayed, improving the query's efficiency.

o Example: Fetch sales records from a specific month instead of the en re dataset.

3. Support Decision-Making
Criteria allow users to focus on ac onable data, aiding in analysis and decision-making.

o Example: Iden fy customers who haven’t made a purchase in the last six months.

4. Enable Dynamic Interac on


Using parameterized criteria, queries can prompt users for input, making the database more
interac ve.

o Example: Ask the user to input a city name and retrieve all customers from that city.

Common Uses of Criteria in Queries

1. Equality Condi ons:

o Match exact values.

o Example: City = 'New York' retrieves all records where the city is New York.

2. Range Condi ons:

o Filter data within a specific range.

o Example: Salary BETWEEN 30000 AND 50000 retrieves salaries in the given range.

3. Pa ern Matching:

o Use wildcards to search for pa erns.

o Example: Name LIKE 'A%' retrieves all names star ng with 'A'.

4. Comparison Condi ons:

o Compare values using operators like <, >, <=, >=, etc.
o Example: Age > 18 retrieves all records where the age is above 18.

5. Logical Operators:

o Combine mul ple condi ons using AND, OR, or NOT.

o Example: (City = 'London') AND (Salary > 40000) retrieves all records mee ng both
condi ons.

6. Null or Not Null:

o Check for missing or present values.

o Example: Email IS NOT NULL retrieves all records with an email address.

Examples of Using Criteria

1. Basic Filtering:
A query with the criterion Product_Price > 100 retrieves all products priced above $100.

2. Mul ple Condi ons:


A query with (Category = 'Electronics') AND (Stock > 10) retrieves all electronic items with
stock greater than 10.

3. Date-Based Criteria:
A criterion like Order_Date >= '2025-01-01' retrieves all orders placed on or a er January 1,
2025.

4. Parameterized Query:
A query with City = [Enter City] prompts the user to input a city name dynamically.

Benefits of Using Criteria in Queries

1. Data Precision: Focus on only the necessary records.

2. Time-Saving: Avoid si ing through irrelevant data manually.

3. Dynamic Interac ons: Allow users to customize data retrieval based on their needs.

4. Improved Decision-Making: Provide targeted insights by filtering out irrelevant informa on.

Conclusion

Criteria in queries are essen al for refining data retrieval processes in a database. They enable users
to apply condi ons that filter, sort, and focus on specific subsets of data, making database
interac ons more precise, efficient, and meaningful. By leveraging criteria effec vely, users can
transform raw data into ac onable insights.
QS- 3 What Are Parameterized Queries? [5 or 10 marks]

A parameterized query is a type of query that uses placeholders, also known as parameters, instead
of hard-coded values. These parameters are replaced with actual values at run me, either provided
by the user or programma cally through an applica on. Parameterized queries enhance flexibility,
security, and reusability in database opera ons.

Key Features of Parameterized Queries

1. Dynamic Input: Accept user input or variable data during execu on.

2. Reusability: The same query can be executed with different parameter values.

3. Security: Prevent SQL injec on a acks by trea ng user input as data, not executable code.

4. Ease of Maintenance: Reduces the need to rewrite queries for different input values.

Components of a Parameterized Query

1. Placeholders/Parameters: Indicate where the run me value will be inserted. These can be
represented as ? or named parameters like :param_name depending on the database.

2. Input Values: Supplied by the user or applica on to replace the placeholders at run me.

3. Execu on: The database engine processes the query by subs tu ng the placeholders with
the provided values.

Examples of Parameterized Queries

1. Using SQL Placeholder (?)

SELECT * FROM Students WHERE Grade = ?;

When executed, the placeholder ? will be replaced with a specific grade value like 10 or 12.

2. Named Parameters (e.g., in Python)

query = "SELECT * FROM Employees WHERE Department = :dept AND Salary > :salary;"

params = {'dept': 'HR', 'salary': 50000}

cursor.execute(query, params)

Here, :dept and :salary are replaced with HR and 50000 during execu on.

3. In LibreOffice Base

In LibreOffice Base, a parameterized query might prompt the user for input dynamically. For
example:
SELECT * FROM Orders WHERE Order_Date >= [Enter Start Date];

When executed, the database prompts the user to enter a start date, which replaces the [Enter Start
Date] placeholder.

Uses of Parameterized Queries

1. Dynamic Data Retrieval:

o Allows users to input search criteria at run me.

o Example: Fetch products within a price range entered by the user.

2. Security Against SQL Injec on:

o Prevents malicious input from being executed as part of the query.

o Example: If a user inputs ' OR 1=1 --, it will be treated as data, not code.

3. Flexible Applica on Design:

o Supports crea ng reusable queries for varying user inputs.

o Example: A report-genera ng tool that accepts date ranges or customer IDs.

4. Improved Performance:

o Prepares the query structure once, allowing the database engine to op mize
execu on for mul ple runs with different parameters.

Advantages of Parameterized Queries

1. Security:

o Prevents SQL injec on a acks by dis nguishing data from code.

2. Efficiency:

o Reduces query parsing and op miza on overhead for repeated execu ons.

3. Flexibility:

o Allows the same query structure to work with different inputs.

4. Readability:

o Makes code easier to read and maintain by separa ng query logic from data.

Disadvantages of Parameterized Queries

1. Learning Curve:

o Requires understanding of placeholders and parameter binding.

2. Limited Flexibility for Complex Scenarios:


o May need addi onal logic for dynamic query structures.

3. Dependency on the Database/Driver:

o Parameter syntax varies across database systems (e.g., ? for SQLite, :name for
PostgreSQL).

Conclusion

Parameterized queries are a powerful tool in database management, offering enhanced security,
flexibility, and efficiency. By replacing hard-coded values with parameters, they enable dynamic input
handling while protec ng against SQL injec on a acks. Widely used in modern applica ons,
parameterized queries are a best prac ce for interac ng with databases securely and effec vely.

You might also like