0% found this document useful (0 votes)
767 views4 pages

Class 11 Notes Informatics Practices Chap 8 (2024-25)

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

Class 11 Notes Informatics Practices Chap 8 (2024-25)

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

NOTES

CLASS 11TH
SUBJECT - INFORMATICS PRACTICES
CHAPTER – 8 INTRODUCTION TO STRUCTURED QUERY
LANGUAGE (SQL)

1. Introduction to SQL
Structured Query Language (SQL) is a standard programming language used to manage and
manipulate relational databases. It allows users to perform various tasks such as retrieving,
updating, inserting, and deleting data within a database.
SQL is divided into different categories based on functionality:
 DDL (Data Definition Language): Defines and modifies database structures.
 DML (Data Manipulation Language): Handles data manipulation operations.
 DCL (Data Control Language): Deals with permissions and security.
 TCL (Transaction Control Language): Manages database transactions.
 DQL (Data Query Language) : eg. SELECT

2. Components of SQL
SQL consists of the following key components:
 Commands: Predefined instructions that perform specific tasks (e.g., SELECT, INSERT,
DELETE).
 Clauses: Components that form SQL statements (e.g., WHERE, ORDER BY).
 Expressions: Combinations of variables, operators, and values that SQL uses to
generate results.
 Predicates: Conditions used in SQL queries (e.g., comparisons and logical operations).

3. SQL Data Types


SQL provides various data types to define the kind of data that can be stored in each column
of a database table:
 CHAR(n): A fixed-length string with 'n' characters.
 VARCHAR(n): A variable-length string with up to 'n' characters.
 INT: An integer number.
 FLOAT: A floating-point number.
 DATE: Date values (in YYYY-MM-DD format).
 BOOLEAN: Represents true or false values.

4. Types of SQL Commands


SQL commands can be categorized as:
a. Data Definition Language (DDL)
DDL commands are used to define or modify the structure of a database.
 CREATE: Defines a new table, view, or database.
 ALTER: Modifies an existing database object, such as a table.
 DROP: Deletes an existing database object, such as a table or view.
 TRUNCATE: Removes all rows from a table without deleting the structure.
b. Data Manipulation Language (DML)
DML commands are used to manage data within tables.
 SELECT: Retrieves data from a table.
 INSERT: Adds new records into a table.
 UPDATE: Modifies existing records in a table.
 DELETE: Removes records from a table.
c. Data Control Language (DCL)
DCL commands are used to control access to data in the database.
 GRANT: Gives user access privileges to the database.
 REVOKE: Removes user access privileges.
d. Transaction Control Language (TCL)
TCL commands manage transactions within a database.
 COMMIT: Saves the changes made during the current transaction.
 ROLLBACK: Undoes changes made during the current transaction.
 SAVEPOINT: Creates a point within a transaction to which a rollback can occur.
 SET TRANSACTION: Configures the properties of a transaction.

5. SQL Query Structure


An SQL query typically follows this general syntax:
sql
SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column_name;Where:
 SELECT: Specifies the columns to be retrieved.
 FROM: Indicates the table from which data is retrieved.
 WHERE: Filters the data based on a condition.
 ORDER BY: Orders the result set by one or more columns.

6. SQL Operators
Operators in SQL are used to perform operations on data:
 Arithmetic Operators: Used to perform mathematical calculations.
o + (Addition), - (Subtraction), * (Multiplication), / (Division), % (Modulus).
 Comparison Operators: Used to compare data.
o = (Equal), <> or != (Not equal), > (Greater than), < (Less than), >= (Greater
than or equal to), <= (Less than or equal to).
 Logical Operators: Used to combine multiple conditions.
o AND, OR, NOT.
 BETWEEN: Filters the data within a specified range.
 IN: Checks if a value matches any value in a list.
 LIKE: Searches for a specified pattern in a column.

7. SQL Clauses
Clauses are components used to define SQL queries:
 SELECT: Specifies the columns to be selected from a table.
 FROM: Indicates the table to retrieve the data from.
 WHERE: Adds conditions to filter the result set.
 ORDER BY: Sorts the result set in ascending or descending order.
 GROUP BY: Groups rows that have the same values into summary rows.
 HAVING: Filters groups after the GROUP BY clause.
 JOIN: Combines rows from two or more tables based on a related column.
8. SQL Functions
SQL provides several functions to perform calculations and operations on data:
 Aggregate Functions: Perform a calculation on a set of values and return a single
value.
o COUNT(), SUM(), AVG(), MAX(), MIN().
 Scalar Functions: Operate on a single value and return a single value.
o UPPER(), LOWER(), LENGTH(), ROUND(), NOW().

9. Keys in SQL
Keys are important for maintaining the integrity and structure of a database:
 Primary Key: A unique identifier for each record in a table.
 Foreign Key: A field that links to the primary key of another table.
 Composite Key: A primary key made up of more than one column.
 Candidate Key: A column or set of columns that can uniquely identify a row, but is
not necessarily chosen as the primary key.

10. Normalization in SQL


Normalization is the process of organizing data in a database to avoid redundancy and
dependency. The goals of normalization include:
 Eliminating data redundancy.
 Ensuring data integrity.
 Improving query performance.
The normalization process is divided into several normal forms:
 1st Normal Form (1NF): Ensures that each column contains atomic values and each
record is unique.
 2nd Normal Form (2NF): Achieved by removing partial dependency (non-key
attributes should depend on the whole primary key).
 3rd Normal Form (3NF): Ensures that there are no transitive dependencies (non-key
attributes depend only on the primary key).

11. Indexing in SQL


Indexes are used to speed up the retrieval of rows from a table. They are created on
columns frequently used in queries' WHERE clauses, ORDER BY clauses, or as part of a JOIN.
Types of indexes:
 Unique Index: Ensures that the values in the indexed column(s) are unique.
 Primary Index: Created on the primary key column.

12. Constraints in SQL


Constraints are used to ensure the accuracy and reliability of data within a database table.
Common types of constraints include:
 NOT NULL: Ensures that a column cannot have a NULL value.
 UNIQUE: Ensures all values in a column are distinct.
 CHECK: Ensures that all values in a column satisfy a specific condition.
 DEFAULT: Sets a default value for a column if no value is provided.
 FOREIGN KEY: Ensures referential integrity between two tables.

13. Conclusion
SQL is a powerful language used for managing and manipulating relational databases.
Mastery of SQL allows for efficient database design and data retrieval. It is essential for
performing tasks like querying data, updating records, and ensuring database integrity
through normalization and constraints.

You might also like