SQL Notes
SQL Notes
SQL Notes
Structured Query Language (SQL) is a language used to access and manipulate data on relational
databases.
5. DQL: Data Query Language - Used to retrieve data from databases or tables.
SELECT: Used to retrieve or return the required data from a table.
FROM: Used to select the table from which data is obtained.
ORDER BY: Used to sort the data retrieved by a certain column.
GROUP BY: Used to group retrieved data by a specific column. Aggregates the data.
HAVING: Used to filter the aggregated data based on a specified condition.
6. DML: Data Manipulation Language - Used to Modify the data that present in the SQL table.
Insert: Used to add new rows of data to a table.
Delete: Used to remove or delete one or more rows of data from a table.
Update: Used to modify existing data in a table.
7. DCL: Data Control Language - Used to control the access the data.
GRANT: Used to give user access to a database.
REVOKE: Used to take away user access to a database.
8. TCL: Transaction Control Language – Used to manage and control the transactions.
COMMIT: Used to save all changes made within a transaction.
ROLLBACK: Used to revert or undo all changes made within a transaction.
SAVE POINT: Used to set a specific point in a transaction to which changes can be rolled back.
9. What is MySQL?
It is freely available open-source RDBMS (Relational Database Management System) that uses
SQL. Information is stored in the form of table in MySQL Database. A single MySQL database can
contain many tables at once and stored thousands of records.
10. What is Importance of MySQL?
It provides strong data security.
It gives high performance.
Saves the cost as it is free.
On demand scalability
11. What is difference between SQL Language and MySQL Programming Language?
SQL stands for Structured Query Language. It's a special language used to communicate with
databases. Think of it as a way to talk to a database and ask it for information.
Imagine you have a big collection of data, like a list of books in a library. If you wanted to find all
the books by a certain author, you could ask using SQL. It helps you retrieve, update, and
manage data in a database.
MySQL, on the other hand, is a specific program that uses SQL. It's like a tool that understands
and executes the instructions you give in SQL.
Now, let's break down some basic SQL concepts:
1. Tables 2. Queries 3. Select 4. Insert 5. Update 6. Delete
MySQL itself relational database that uses SQL as the standard database language.
NoSQL databases are nontabular databases that store data in JSON documents instead of
relational databases.
Databases are often created using formal design and Modeling approaches, and they are usually
managed using a Database Management System (DBMS).
Few examples of RDBMS are MySQL, Oracle, and Microsoft SQL Server.
DBMS RDBMS
It stores data as a file. It stores data in the form of tables.
It only supports a single user. It supports multiple users.
It stores data which are not related to each Data stored in tables are related via foreign
other. keys.
Data fetching is slower for the complex and Data fetching is rapid because of the
large volumes of data. relational approach.
It has no security. It has multiple levels of security.
Examples: File System, XML, MS Access Examples: MySQL, PostgreSQL, Oracle, and
SQL Server
I. String
II. Numeric
III. Date and Time
DELETE command is used to delete a specific row from the table whereas the TRUNCATE
command is used to remove all rows from the table.
We can use the DELETE command with the WHERE clause but cannot use the TRUNCATE
command with it.
TRUNCATE removes all rows from the table which cannot be retrieved back.
DROP removes the entire table from the database, and it also cannot be retrieved back.
Table View
1. Tables are database objects with unique 1. Views are virtual tables in SQL that are
names which consist of a collection of created by selecting fields from one or
data stored in a database. more tables present in the database
2. Tables contains data and exist physically 2. Views do not contain any data and do not
in the database. exist physically in the database
3. A table is an independent data object. 3. Views depends on tables.
34. What is the difference between Local and Global temporary tables?
Local temporary table exists only for the duration of that statements. Global temporary table
exists permanently in the database, but its rows disappear when the connection is closed.
35. What is the difference between the HAVING clause and WHERE clause?
Both specify search condition but Having clause is used only with select statement but usually
used with Group By Clause. If the Group By Clause is not used, then Having clause behave like a
where clause.
Data Manipulation in My SQL :
The following are the most important SQL commands for database manipulation.
CREATE DATABASE
SHOW DATABASE
USE
DROP DATABASE
To lists all database in the Mysql database, use the SHOW DATABASE statement.
The DROP DATABASE statement is used to delete all tables in an existing database and
permanently delete that database.
It is necessary to notify mysql about the destination database before interacting with it.
To select an existing database from the mysql database use the USE Statement.
To View the existing selected Database from Mysql database, we use the SELECT
DATABASE() Statement.
Data type refer to the nature or format of data that is entered into a columns of the table. In
the simple words, the data type reflects the kind of information stored in the field.
String
Numeric
Date and time
Numeric : It has only a number or a number with decimal places ( Ex : 120130 or 230.15 )
Date and Time : It contains date and time ( Ex : 120130 , 23:10:00 , 20210526 23:10:00 )