Introduction To SQL
Introduction To SQL
SQL is a powerful language for managing and manipulating relational databases. This presentation will cover the
fundamentals of SQL, including different command types, data types, and syntax.
SQL Command Types
Commands to create, modify, and Commands to insert, update, delete, Commands to control access and
delete database objects like tables, and select data from tables. permissions for database objects and
views, and indexes. data.
IUDS GR
CADTCR
SQL Data Types
1 Numeric
INT, DECIMAL, FLOAT, BIT
2 Text
CHAR, VARCHAR, TEXT
3 Date/Time
DATE, TIME, DATETIME, TIMESTAMP
Default Database in
SQL Server
1 Master
The default system database in SQL Server
2 Model
Template used to create new databases
3 Temp Database
The database is use to hold temporary data .
DELETE Command
Syntax
DELETE FROM table_name WHERE condition;
Purpose
Remove one or more rows from a table
DROP Command
Syntax
DROP TABLE table_name;
Purpose
Completely remove a table from the database
TRUNCATE vs. DELETE vs DROP
TRUNCATE DELETE
Removes all rows from a table, but the table Removes rows from a table based on a condition
structure remains
Logs each row deletion, allowing for rollback
Faster than DELETE .
Slower than TRUNCATE.
Modifies the values of existing rows in a table Modifies the structure of a table, such as
adding or removing columns
Uses a WHERE clause to target specific rows
Doesn't change the data in the table
Doesn't change the table structure
SQL Aliases
Table Aliases
Provide shorter names for tables in queries
Column Aliases
Rename columns to be more descriptive
Benefits
Improve readability .
WHERE vs. HAVING
WHERE
Filters rows before aggregation, based on column values.
HAVING
Filters groups after aggregation, based on aggregate
functions.
AND vs. OR
AND OR
Combines conditions, returns rows that meet all Combines conditions, returns rows that meet
conditions. any condition.
LIKE
LIKE
Performs pattern matching on string data.
UNION vs. UNION ALL
Combines result sets, removes duplicate rows. Combines result sets, includes all rows,
including duplicates.
Aggregate Functions
1 SUM
Calculates the total of a numeric column.
2 AVG
Calculates the average of a numeric column.
3 COUNT
Counts the number of rows in a result set.
4 MIN/MAX
Returns the minimum or maximum value in a column.
SQL Joins
Returns rows where the join Returns all rows from one table and
condition is met in both tables. the matching rows from the other
table.
Inner Join
Table 1
Id Name
1 Ram
2 Radha
Syntax
Null Ramya
SELECT * FROM table1 INNER
Table 2
JOIN table2 ON table1.column =
table2.column;
NO Salary
1 2000
2 5000
NULL 10000
3 4000
Left Join
Syntax
Syntax