0% found this document useful (0 votes)
7 views

XII IP Notes Database

The document provides an overview of database concepts, including definitions of data, databases, and the differences between file systems and database management systems (DBMS). It covers key elements such as relational data models, keys, SQL commands for data definition and manipulation, and various constraints. Additionally, it highlights the differences between DDL and DML, as well as comparisons between various SQL functions and commands.
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)
7 views

XII IP Notes Database

The document provides an overview of database concepts, including definitions of data, databases, and the differences between file systems and database management systems (DBMS). It covers key elements such as relational data models, keys, SQL commands for data definition and manipulation, and various constraints. Additionally, it highlights the differences between DDL and DML, as well as comparisons between various SQL functions and commands.
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/ 3

- Foreign Key: A field in one table that refers to the

Database Concepts primary key of another table, creating a link between


them.
1. Introduction
- Data: Raw facts that can be processed to generate 5. Database Schema & Constraints
meaningful information. - Database Schema: The structural design defining tables,
- Database: An organized collection of structured data that attributes, and relationships.
can be easily accessed, managed, and updated. - Constraints: Rules enforced to maintain data integrity
(e.g., NOT NULL, UNIQUE, FOREIGN KEY constraints).
2. File System vs. Database Management System (DBMS) - Metadata: Data about data, such as schema definitions
- File System: Traditional data storage method using stored in the system catalog.
separate files, leading to redundancy and inconsistency.
- DBMS (Database Management System): A software 6. Querying and Data Manipulation
system that enables efficient management of structured - Query: A structured request to retrieve or modify data.
data within a database. - Data Manipulation Operations:
- Insertion: Adding new records.
Limitations o File Systems - Deletion: Removing records.
- Data Redundancy: Duplication of data across multiple - Update: Modifying existing records.
files.
- Data Inconsistency: Mismatched data across different 7. Real-Life Applications of Databases
files due to redundant storage. - Banking: Managing customer accounts and transactions.
- Data Isolation: Separate files cannot be efficiently linked - Inventory Management: Tracking product details and
to retrieve related data. stock levels.
- Controlled Data Sharing: Difficulty in restricting access to - Education: Storing student attendance, grades, and
sensitive information. guardian details.
- E-Commerce: Managing customer preferences and order
Advantages o DBMS history.
- Centralized Data Storage: Reduces redundancy and
ensures consistency.
- Efficient Data Retrieval: Structured queries allow faster Introduction to SQL
access to required information. - Relational Database Management System (RDBMS): A
- Data Integrity: Ensures data accuracy and consistency. database system that organizes data in relations (tables)
- Security and Access Control: Allows user-level and allows structured querying.
permissions for secure data access. - SQL (Structured Query Language): A standardized
programming language used for managing and querying
3. Relational Data Model data in an RDBMS.
- Relational Model: Organizes data into structured tables,
ensuring relationships between records. Data Types in MySQL
- Relation (Table): A collection of data organized in rows Data Type: Defines the kind of values a column can store.
and columns. - CHAR(n): A fixed-length character type; space is reserved
- Tuple (Row): A single data entry in a table representing for `n` characters.
an entity. - VARCHAR(n): A variable-length character type; space
- Attribute (Column): A characteristic describing each allocated depends on the actual string length.
entity in a table. - INT: Stores integer values, occupying 4 bytes.
- Domain: The set of possible values for an attribute. - BIGINT: Stores larger integer values, occupying 8 bytes.
- Degree: Number of attributes (columns) in a relation. - FLOAT: Holds numbers with decimal points, occupying 4
- Cardinality: Number of tuples (rows) in a relation. bytes.
- DATE: Stores date values in the format `'YYYY-MM-DD'`.
4. Keys in a Relational Database
- Candidate Key: Any attribute(s) that uniquely identifies Constraints in MySQL
tuples in a relation. Constraint: A rule imposed on column values to maintain
- Primary Key: A chosen candidate key used for unique data accuracy.
identification. - NOT NULL: Ensures a column cannot have missing values.
- Composite Primary Key: A primary key consisting of - UNIQUE: Ensures all values in a column are distinct.
multiple attributes. - DEFAULT: Assigns a default value if none is provided.
- PRIMARY KEY: Uniquely identifies each row in a table.
- FOREIGN KEY: Establishes a relationship between two SQL or Data Query
tables by referring to a primary key in another table. Query: A request for retrieving specific data from a
database.
SQL or Data Definition - SELECT: Retrieves data from one or more tables.
Data Definition Language (DDL): A set of SQL commands - WHERE: Filters records based on specified conditions.
that define database structures. - ORDER BY: Sorts query results in ascending or
- CREATE DATABASE: Used to create a new database. descending order.
- CREATE TABLE: Defines a table's attributes (columns) and - DISTINCT: Returns unique values in a column.
their data types. - LIKE: Used for pattern matching in text-based searches
- ALTER TABLE: Modifies the structure of an existing table (`%` for multiple characters, `_` for a single character).
(e.g., adding/removing columns). - BETWEEN: Defines a range for filtering results.
- DROP TABLE: Permanently removes a table from a - IN: Checks if a value matches any value in a specified list.
database. - IS NULL: Identifies missing values.

SQL for Data Manipulation Data Updation and Deletion


Data Manipulation Language (DML): A set of SQL - UPDATE: Modifies values in a table.
commands that manage the data within tables. - DELETE: Removes records from a table, with caution to
- INSERT INTO: Adds new records to a table. use `WHERE` to target specific rows.
- UPDATE: Modifies existing records in a table. - DROP: Permanently deletes an entire table or database.
- DELETE: Removes specific records from a table.

Differences
1) DDL vs. DML
Feature DDL (Data Definition Language) DML (Data Manipulation Language)
Defines database structure (tables, schemas, Manipulates existing data (insert, update, delete,
Purpose
constraints). retrieve).
Commands CREATE, ALTER, DROP, TRUNCATE SELECT, INSERT, UPDATE, DELETE
Effect on Data Changes table structure, not data. Modifies data within tables.
Rollback
Generally not possible (except some cases). Supports ROLLBACK to undo changes.
Option
2) WHERE vs. HAVING Clause
Feature WHERE Clause HAVING Clause
Filters individual rows before
Purpose Filters aggregated groups after using GROUP BY.
aggregation.
SELECT with aggregate functions (SUM, AVG,
Used With SELECT, UPDATE, DELETE
etc.).
SELECT dept, AVG(salary) FROM
SELECT * FROM students WHERE
Example employees GROUP BY dept HAVING
age > 18;
AVG(salary) > 50000;
3) Single Row Functions vs. Multi Row Functions
Feature Single Row Functions Multi Row Functions
Operates on individual rows and returns one result per Operates on a set of rows and returns a single
Definition
row. value.
Examples UPPER(), LOWER(), LENGTH(), ROUND(), ABS() COUNT(), SUM(), AVG(), MAX(), MIN()
Use
Formatting data, manipulating values within a row. Aggregating data across multiple rows.
Cases
4) DELETE vs. DROP Commands
Feature DELETE DROP
Purpose Removes specific records from a table. Removes an entire table from the database.
Effect on Table Table structure remains intact. Table and its data are permanently removed.
Rollback Option Possible with ROLLBACK. Not possible once executed.
Example DELETE FROM students WHERE age < 18; DROP TABLE students;
5) Primary Key vs. Foreign Key vs. Unique Key
Feature Primary Key Foreign Key Unique Key
Uniquely identifies records Links one table to another using a Ensures uniqueness but allows
Purpose
in a table. reference. NULL values.
Number Can have multiple foreign keys
Only one per table. Multiple unique keys per table.
Allowed per table.
NULL Yes (if not explicitly set to NOT
No Yes
Allowed? NULL).
6) Candidate Key vs. Primary Key vs. Alternate Key
Feature Candidate Key Primary Key Alternate Key
A column (or set of columns) that The selected candidate key used Remaining candidate keys after
Definition
can uniquely identify each row. to uniquely identify rows. choosing a primary key.
Number Multiple candidate keys exist in a Depends on the number of
Only one primary key per table.
Allowed table. candidate keys.
(AdmNo, Aadhaar Number) in a AdmNo (chosen as primary Aadhaar Number (alternate
Example
student table. key). key).
7) CHAR vs. VARCHAR
Feature CHAR VARCHAR
Definition Fixed-length character storage. Variable-length character storage.
Storage Uses space dynamically, adjusting based on
Uses allocated space even if characters are fewer.
Efficiency stored characters.
Best for short, fixed-length strings (e.g., country Best for storing variable-length data (e.g.,
Use Case
codes, status values). names, addresses).
VARCHAR(10) only stores exact character
Example CHAR(10) always reserves space for 10 characters.
count.

You might also like