SQL Notes

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

1. What is SQL?

Structured Query Language (SQL) is a language used to access and manipulate data on relational
databases.

2. Why SQL Important?


SQL is important for managing big data, allowing users to easily search, sort, and analyze large
datasets.

3. What are the SQL Commands?


SQL commands are used to interact with databases and help users perform various operations
such as creating databases or tables, inserting data, and retrieving data.

 DDL: Data Definition Language - Used to define database structure.


 DQL: Data Query Language - Used to retrieve data from databases or tables.
 DML: Data Manipulation Language - Used to Modify the data that present in the SQL table.
 DCL: Data Control Language - Used to control the access the data.
 TCL: Transaction Control Language – Used to manage and control the transactions.

4. DDL: Data Definition Language - Used to define database structure.


 CREATE: Used to create a new table or database.
 ALTER: Used to modify the structure of an existing table.
 RENAME: Used to change the name of an existing table or column.
 TRUNCATE: Used to delete all data from a table.
 DROP: Used to delete an entire table or database.

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

12. What is the difference between SQL and MySQL?


SQL is a Structured Query Language that is used for access and manipulating data on relation
database.

MySQL itself relational database that uses SQL as the standard database language.

13. What is the difference between SQL and NOSQL?


SQL is a Structured Query Language that is used for access and manipulating data on relation
database.

NoSQL databases are nontabular databases that store data in JSON documents instead of
relational databases.

14. What is the difference between SQL and PL/SQL?


SQL is a Structured Query Language that is used for access and manipulating data on relation
database whereas PL/SQL comes with procedural concepts of programming languages.

15. What is Data?


Data is described as fact, numbers and other forms of information that are generally stored and
it can be smaller volume. Data can be several forms, including text, number and bits and bytes.

16. What is Database?


Database is collection of data that can stored in computer so that it can be accessed, managed,
and updated easily.

Databases are often created using formal design and Modeling approaches, and they are usually
managed using a Database Management System (DBMS).

17. Types Of Databases?


 Relational Database
 NoSQL Database
 Graph Database
 Centralized and Distributed Database

18. What is Database Management System (DBMS)?


A database management system (DBMS) is a software that stores and retrieves data based on
the user’s requirements. DBMS acts as an interface between the data and software.

19. What is Relational Database Management System (RDBMS)?


A relational database management system (RDBMS) is an advanced version of a database
management system (DBMS). It is the most popular DBMS in the market.

Few examples of RDBMS are MySQL, Oracle, and Microsoft SQL Server.

20. What is difference between DBMS and RDBMS?

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

21. What is the Database Manipulation commands in MySQL?


The followings are the most important commands for Databases in the MYSQL database.

 Create Database - Create new database in MySQL.


 Show Database - To see or list all databases which were created in MYSQL.
 Use – Use this command for interacting database in MySQL.
 Drop Database – Delete the existing databases permanently from MySQL.

22. What is Data Type?


Data types refer to the nature or format of the data that can be entered into a database.

Data types are divided into three categories.

I. String
II. Numeric
III. Date and Time

23. What are the tables in MySQL?


Tables are in database with unique names which consist of a collection data stored in a
database.
 A Table is collection of number of rows and columns.
24. What are the table manipulation commands in MySQL?
The followings are the most important commands for tables in the MYSQL database.
 CREATE TABLE - Creating new table in the database.
 SHOW TABLES - To see or list all TABLES which were created in MySQL.
 DESCRIBE - view the table structure of the table.
 DROP TABLE - delete existing table permanently from the MYSQL database.
 Insert Into – Used to add new rows data to table.
 TRUNCATE TABLE - delete all data in the existing table.
 ALTER TABLE - Used to modify the structure of an existing table and
perform below actions.
(a) Adding columns to a Table.
(b) Modify columns to a table.
(c) Renaming columns in a table.
(d) Dropping columns in a table.
(e) Renaming Table.

25. What are the table Rows manipulation commands in MySQL?


Update: - Used to modify existing data in a table. update is the command which is used to
update values at place. Here “SET” is used to setting the new values and “WHERE” Clause used
to refer old balance.

Delete: - Used to remove one or more rows of data from a table.

26. What are the different clauses used in SQL?


 Select: Returns or retrieve the required data
 From: Specifies or select the table from which the data is obtained or retrieved.
 Where: Applies the condition to filter data
 Order By: Used to sort the data retrieved by a certain column in ASC/DESC Order.
 Group By: Used to group retrieved data by a specific column. It Aggregate the data.
 Having: Used to filter data based on a specified condition. Filter the aggregated data.
 Join: Derives common data from a different table.

27. What is the Order of Execution in the SQL?


Below one the order of execution in the SQL. We must explain in the below order.
 From: Specifies or select the table from which the data is obtained or retrieved.
 Join: Derives common data from a different table.
 Where: Applies the condition to filter data
 Group By: Used to group retrieved data by a specific column. It Aggregate the data.
 Having: Used to filter data based on a specified condition. Filter the aggregated data.
 Select: Returns or retrieve the required data.

28. How to select all records from the table?


To select all records from the table, follow the below syntax:
Select * from table_name;

29. What is difference between Truncate, Delete and Drop?


The basic difference between this Truncate command is DDL command, delete command is DML
command, drop command is DDL Command.

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.

30. What is Relationship in MySQL?


A relationship is a condition that exists between two tables in a database when data from one
table reflects data from another table.
 Two tables are required to form a table relationship at the same time, one of which is
called the primary or parent table and the other the related or child table.

31. What are Views in MySQL?


Views are virtual table in SQL that are created by selecting fields from one or more tables
present in the database.

32. What is difference between table and View?

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.

33. What is CTE?


CTE or Common Table Expression contains temporary results set which is defined in SQL
Statements.

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

1. Creating database in My SQL :

To build a new Mysql database, use the CREATE DATABASE.

Syntax : CREATE DATABASE database_name;

2. Listing available database in My SQL :

To lists all database in the Mysql database, use the SHOW DATABASE statement.

Syntax : SHOW DATABASE;

3. Deleting Database in My SQL :

The DROP DATABASE statement is used to delete all tables in an existing database and
permanently delete that database.

Syntax : DROP DATABASE database_name;

4. Database selection in My SQL

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.

Syntax for selecting a default database

Syntax : USE database_name;

Syntax for getting the name of the default database

Syntax : select Database () ;


Data Types :

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.

We have three categories of data types :

 String
 Numeric
 Date and time

String : It contains letters, numbers, and special characters ( Ex : TN2315@ )

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 )

You might also like