Structured Query Language (SQL)
SQL
1. Introduction to SQL
1.1 What is SQL?
- SQL (Structured Query Language) is a standard programming language used to manage and manipulate relational databases.
- SQL allows you to perform various tasks such as querying data, updating records, deleting records, and creating or modifying database structures.
1.2 SQL Syntax
- SQL statements are written in uppercase for readability, though SQL is case-insensitive.
- SQL commands are executed using a database management system (DBMS) like MySQL, PostgreSQL, SQL Server, etc.
2. SQL Data Types
SQL provides several data types for defining columns in tables. Here are some common ones:
- INT: Integer values.
- VARCHAR(size): Variable-length string (e.g.,
VARCHAR(255)). - TEXT: Large text strings.
- DATE: Date values in the format YYYY-MM-DD.
- FLOAT: Floating-point numbers.
3. Basic SQL Operations
3.1 SELECT Statement
The SELECT statement is used to query data from a table.
- The
*symbol selects all columns from the table.
3.2 WHERE Clause
The WHERE clause is used to filter records.
3.3 ORDER BY Clause
The ORDER BY clause is used to sort results in ascending (ASC) or descending (DESC) order.
3.4 DISTINCT Keyword
The DISTINCT keyword is used to select unique values.
4. SQL Functions
4.1 Aggregate Functions
- COUNT(): Returns the number of rows that match the criteria.
- SUM(): Returns the sum of a numeric column.
- AVG(): Returns the average value of a numeric column.
- MAX(): Returns the maximum value in a column.
- MIN(): Returns the minimum value in a column.
5. SQL Joins
5.1 INNER JOIN
An INNER JOIN returns records that have matching values in both tables.
5.2 LEFT JOIN (LEFT OUTER JOIN)
A LEFT JOIN returns all records from the left table and matched records from the right table. If no match is found, NULL values are returned for columns from the right table.
5.3 RIGHT JOIN (RIGHT OUTER JOIN)
A RIGHT JOIN returns all records from the right table and matched records from the left table. If no match is found, NULL values are returned for columns from the left table.
5.4 FULL OUTER JOIN
A FULL OUTER JOIN returns all records when there is a match in either the left or right table. Rows that don’t match in either table will have NULL values.
6. SQL Insert, Update, and Delete
6.1 INSERT INTO Statement
The INSERT INTO statement is used to insert new records into a table.
6.2 UPDATE Statement
The UPDATE statement is used to modify existing records in a table.
6.3 DELETE Statement
The DELETE statement is used to remove records from a table.
7. SQL Constraints
7.1 PRIMARY KEY
A PRIMARY KEY is a column or a set of columns that uniquely identifies each row in a table.
7.2 FOREIGN KEY
A FOREIGN KEY is a column that creates a relationship between two tables. It links to the primary key in another table.
7.3 UNIQUE
The UNIQUE constraint ensures that all values in a column are unique.
7.4 NOT NULL
The NOT NULL constraint ensures that a column cannot have NULL values.
8. SQL Subqueries
8.1 Subquery in SELECT Statement
A subquery is a query within another query.
8.2 Subquery in WHERE Clause
A subquery can be used in the WHERE clause to filter results.
9. SQL Data Definition Language (DDL)
- CREATE TABLE: Defines a new table.
- ALTER TABLE: Modifies an existing table.
- DROP TABLE: Deletes a table.
- CREATE INDEX: Creates an index for searching faster.
- DROP INDEX: Deletes an index.
9.1 CREATE TABLE Example
9.2 ALTER TABLE Example
9.3 DROP TABLE Example
10. SQL Transactions
10.1 COMMIT and ROLLBACK
SQL transactions allow you to perform multiple operations as a single unit. If something goes wrong, you can ROLLBACK changes, otherwise, use COMMIT to save them.
Assessment: Regular Tests, Assignments, and Final Project Evaluation
Certification: Certificate of Completion from Disha Institute
Number of Days Depends on your practice and feedback. The more you practice and review your work, the faster you will complete the course.
For Batch time and Fess contact to Below Address and Number.
(MCA / Bsc. I.T / ‘A’ / ‘O’ / CCC / Govt. Certified Domain Skill Trainer )
Disha Institute 153 Vijay Nagar Opp. Rg Pg College W.K Road Meerut
(9411617329 , 9458516690)
Comments
Post a Comment