Unit-3
Unit-3
UNIT III: BASIC SQL:Simple Database schema, data types, table definitions (create, al-
ter), different DML operations (insert, delete, update),Basic SQL querying (select and
project) using where clause, arithmetic & logical operations, SQL functions(Date and
Time, Numeric, String conversion).Creating tables with relationship, implementation of
key and integrity constraints, nested queries, sub queries, grouping, aggregation, ordering,
implementation of different types of joins, view(updatable and non-updatable), relational
set operations.
In this example:
A schema named bookstore is created.
A table named books is defined within that schema with columns
for id, title, author, publication_date, and price.
In this example:
employee_id is an integer that uniquely identifies each employee.
name is a variable-length string for storing employee names.
salary uses the DECIMAL type for precise monetary values.
hire_date stores the date when the employee was hired.
profile_picture can store large binary files like images.
Inserting without specifying columns (must provide values for all columns in order):
INSERT INTO employees
VALUES (105, 'Robert Wilson', 'Finance', 65000);
2. DELETE Operation
The DELETE statement removes rows from a table.
DELETE FROM table_name
WHERE condition;
Examples:
Deleting specific rows:
DELETE FROM employees
WHERE emp_id = 104;
Deleting with multiple conditions:
DELETE FROM employees
WHERE department = 'Sales' AND salary < 50000;
Deleting all rows (be careful!):
DELETE FROM employees;
-- This removes all data but keeps the table structure
3. UPDATE Operation
The UPDATE statement modifies existing data in a table.
Basic Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Examples:
Updating a single column:
UPDATE employees
SET salary = 52000
WHERE emp_id = 101;
Updating multiple columns:
sql
UPDATE employees
SET department = 'Operations', salary = salary * 1.1
WHERE department = 'IT';
Updating with calculations:
sql
UPDATE employees
SET salary = salary * 1.05
WHERE hire_date < '2020-01-01';
Basic SQL Querying (SELECT and PROJECT)
SELECT with WHERE Clause
Retrieve specific columns (projection) and filter rows (selection):