Sitemap
Siddhesh Kumbhar

Siddhesh Kumbhar

Python ๐Ÿ| SQL ๐Ÿ“‚| Machine Learning ๐Ÿ”ข | Tableau ๐Ÿ“Š | Data Science ๐Ÿ’ป | Data Analyst ๐Ÿ“ฐ| Data Scientist | Mechanical Engineer | Data Science Engineer

๐’๐๐‹ ๐œ๐จ๐ฆ๐ฆ๐š๐ง๐๐ฌ.

--

Press enter or click to view image in full size
In this section, we will be discussing types of SQL commands. SQL Commands are divided into five broad categories โ€” DDL, DML, DCL, TCL, and DQL. Each category is further explained below:

๐‘บ๐‘ธ๐‘ณ ๐’Š๐’” ๐’‚ ๐’”๐’•๐’‚๐’๐’…๐’‚๐’“๐’… ๐’๐’‚๐’๐’ˆ๐’–๐’‚๐’ˆ๐’† ๐’‡๐’๐’“ ๐’”๐’•๐’๐’“๐’Š๐’๐’ˆ, ๐’Ž๐’‚๐’๐’Š๐’‘๐’–๐’๐’‚๐’•๐’Š๐’๐’ˆ ๐’‚๐’๐’… ๐’“๐’†๐’•๐’“๐’Š๐’†๐’—๐’Š๐’๐’ˆ ๐’…๐’‚๐’•๐’‚ ๐’Š๐’ ๐’…๐’‚๐’•๐’‚๐’ƒ๐’‚๐’”๐’†๐’”.

๐‘บ๐’•๐’“๐’–๐’„๐’•๐’–๐’“๐’†๐’… ๐‘ธ๐’–๐’†๐’“๐’š ๐‘ณ๐’‚๐’๐’ˆ๐’–๐’‚๐’ˆ๐’†(๐‘บ๐‘ธ๐‘ณ) ๐’‚๐’” ๐’˜๐’† ๐’‚๐’๐’ ๐’Œ๐’๐’๐’˜ ๐’Š๐’” ๐’•๐’‰๐’† ๐’…๐’‚๐’•๐’‚๐’ƒ๐’‚๐’”๐’† ๐’๐’‚๐’๐’ˆ๐’–๐’‚๐’ˆ๐’† ๐’ƒ๐’š ๐’•๐’‰๐’† ๐’–๐’”๐’† ๐’๐’‡ ๐’˜๐’‰๐’Š๐’„๐’‰ ๐’˜๐’† ๐’„๐’‚๐’ ๐’‘๐’†๐’“๐’‡๐’๐’“๐’Ž ๐’„๐’†๐’“๐’•๐’‚๐’Š๐’ ๐’๐’‘๐’†๐’“๐’‚๐’•๐’Š๐’๐’๐’” ๐’๐’ ๐’•๐’‰๐’† ๐’†๐’™๐’Š๐’”๐’•๐’Š๐’๐’ˆ ๐’…๐’‚๐’•๐’‚๐’ƒ๐’‚๐’”๐’† ๐’‚๐’๐’… ๐’‚๐’๐’”๐’ ๐’˜๐’† ๐’„๐’‚๐’ ๐’–๐’”๐’† ๐’•๐’‰๐’Š๐’” ๐’๐’‚๐’๐’ˆ๐’–๐’‚๐’ˆ๐’† ๐’•๐’ ๐’„๐’“๐’†๐’‚๐’•๐’† ๐’‚ ๐’…๐’‚๐’•๐’‚๐’ƒ๐’‚๐’”๐’†. ๐‘บ๐‘ธ๐‘ณ ๐’–๐’”๐’†๐’” ๐’„๐’†๐’“๐’•๐’‚๐’Š๐’ ๐’„๐’๐’Ž๐’Ž๐’‚๐’๐’…๐’” ๐’๐’Š๐’Œ๐’† ๐‘ช๐’“๐’†๐’‚๐’•๐’†, ๐‘ซ๐’“๐’๐’‘, ๐‘ฐ๐’๐’”๐’†๐’“๐’•, ๐’†๐’•๐’„. ๐’•๐’ ๐’„๐’‚๐’“๐’“๐’š ๐’๐’–๐’• ๐’•๐’‰๐’† ๐’“๐’†๐’’๐’–๐’Š๐’“๐’†๐’… ๐’•๐’‚๐’”๐’Œ๐’”.

๐“๐ก๐ž๐ฌ๐ž ๐’๐๐‹ ๐œ๐จ๐ฆ๐ฆ๐š๐ง๐๐ฌ ๐š๐ซ๐ž ๐ฆ๐š๐ข๐ง๐ฅ๐ฒ ๐œ๐š๐ญ๐ž๐ ๐จ๐ซ๐ข๐ณ๐ž๐ ๐ข๐ง๐ญ๐จ ๐Ÿ๐ข๐ฏ๐ž ๐œ๐š๐ญ๐ž๐ ๐จ๐ซ๐ข๐ž๐ฌ ๐š๐ฌ:

  1. ๐ƒ๐ƒ๐‹ โ€” ๐ƒ๐š๐ญ๐š ๐ƒ๐ž๐Ÿ๐ข๐ง๐ข๐ญ๐ข๐จ๐ง ๐‹๐š๐ง๐ ๐ฎ๐š๐ ๐ž

2. ๐ƒ๐๐‹ โ€” ๐ƒ๐š๐ญ๐š ๐๐ฎ๐ž๐ซ๐ฒ ๐‹๐š๐ง๐ ๐ฎ๐š๐ ๐ž

3. ๐ƒ๐Œ๐‹ โ€” ๐ƒ๐š๐ญ๐š ๐Œ๐š๐ง๐ข๐ฉ๐ฎ๐ฅ๐š๐ญ๐ข๐จ๐ง ๐‹๐š๐ง๐ ๐ฎ๐š๐ ๐ž

4. ๐ƒ๐‚๐‹ โ€” ๐ƒ๐š๐ญ๐š ๐‚๐จ๐ง๐ญ๐ซ๐จ๐ฅ ๐‹๐š๐ง๐ ๐ฎ๐š๐ ๐ž

5. ๐“๐‚๐‹ โ€” ๐“๐ซ๐š๐ง๐ฌ๐š๐œ๐ญ๐ข๐จ๐ง ๐‚๐จ๐ง๐ญ๐ซ๐จ๐ฅ ๐‹๐š๐ง๐ ๐ฎ๐š๐ e

Data Definition Language(DDL):

The Data Definition Language is made up of SQL commands that can be used to design the database structure. It simply handles database schema descriptions and is used to construct and modify the structure of database objects in the database. DDL refers to a set of SQL instructions for creating, modifying, and deleting database structures, but not data. A general user, who should be accessing the database through an application, should not execute these instructions. All DDL commands are auto-committed, which means they store all database changes permanently. Different DDL commands that construct the database structure are:

  • CREATE Command: The database or its objects are created with this command (like table, index, function, views, store procedure, and triggers). There are two types of CREATE statements in SQL, one is for the creation of a database and the other for a table.

A database is a systematic collection of data. To store data in a well-structured manner, the first step with SQL is to establish a database. To build a new database in SQL, use the CREATE DATABASE statement.

Syntax: CREATE DATABASE db_name;
db_name : name of the database(any name can be given)

Example: CREATE DATABASE Company;
The above example will create a database named Company.

Weโ€™ve already learned how to create databases. To save the information, weโ€™ll need a table. In SQL, the CREATE TABLE statement is used to make a table. A table is made up of rows and columns, as we all know. As a result, while constructing tables, we must give SQL all relevant information, such as the names of the columns, the type of data to be stored in the columns, the data size, and so on. Letโ€™s look at how to utilize the CREATE TABLE statement to create tables in SQL in more detail.

Syntax: CREATE TABLE table_name(
column1 data_type(size),
column2 data_type(size),
column3 data_type(size),
column4 data_type(size),
โ€ฆ..
);

Here,
table_name is the name of a table,
column1 is the name of the first column,
data_type refers to the type of data that will be stored in this column. For instance, int is used to represent integer data.
size refers to the maximum amount of data that can be stored in a certain column.

Example: CREATE TABLE Employee(Emp_Name VARCHAR2(20), DOB DATE, Mobile INT(10), Email VARCHAR2(20));

The above command will create the table schema that look like:

Emp_NameDOB DATEMobileEmail

  • DROP Command: The DROP command can be used to delete a whole database or simply a table that means entire data will also be deleted. The DROP statement deletes existing objects such as databases, tables, indexes, and views.

Syntax: For dropping table: DROP TABLE table_name;
For dropping database: DROP DATABASE db_name;

Example: DROP TABLE Employee;
DROP DATABASE Company;

The first command in the example will drop the Employee table and the second one will drop the entire database.

  • ALTER Command: In an existing table, this command is used to add, delete/drop, or edit columns. It can also be used to create and remove constraints from a table that already exists.

To add a new column:
Syntax: ALTER TABLE table_name ADD column_name COLUMN-definition;
Example: ALTER TABLE Employee ADD Address VARCHAR2(20);
To modify the existing column:

Syntax: ALTER TABLE MODIFY(COLUMN DEFINITIONโ€ฆ.);

Example: ALTER TABLE Employee MODIFY(Emp_Name VARCHAR2(25));

The above command will modify the โ€˜Emp_Nameโ€™ column to data type VARCHAR2 with size 25.

  • TRUNCATE Command: used to indicate the tableโ€™s extents for deallocation (empty for reuse). This procedure removes all data from a table quickly, usually circumventing a number of integrity checking processes. It was included in the SQL:2008 standard for the first time. It is somewhat equivalent to the delete command.

Syntax: TRUNCATE TABLE table_name;
Example: TRUNCATE TABLE Employee;

The above command will delete the data from the โ€˜Employeeโ€™ table but not the table.

Data Manipulation Language:

The SQL commands that deal with manipulating data in a database are classified as DML (Data Manipulation Language), which covers the majority of SQL statements. Itโ€™s the part of the SQL statement that regulates who has access to the data and the database. DCL statements are grouped together with DML statements. The DML command is not auto-committed, which means it cannot preserve all database modifications permanently. They have the potential to be rolled back.

Different DML commands are:

  • INSERT Command: It is used to insert data into a tableโ€™s row.

Syntax: INSERT INTO TABLE_NAME (col1, col2, col3,โ€ฆ. col N)
VALUES (value1, value2, value3, โ€ฆ. valueN);

Or
INSERT INTO TABLE_NAME
VALUES (value1, value2, value3, โ€ฆ. valueN);

Example: INSERT INTO Employee(Emp_Name, DOB, Mobile, Email)
VALUES(โ€˜Joeโ€™, โ€˜1995โ€“02โ€“16โ€™, 7812865845, โ€˜joe@gmail.comโ€™);

The above command will insert the mentioned values in the โ€˜Employeeโ€™ table.

  • UPDATE Command: In SQL, the UPDATE statement is used to update data in an existing database table. We can use the Alter statement to update single or several columns depending on our needs.

Syntax: UPDATE table_name SET column1 = value1, column2 = value2,โ€ฆ
WHERE condition;

Here,
table_name: name of the table
column1: name of first , second..
value1: new value for first, secondโ€ฆ.
condition: condition to select the rows for which the values of columns need to be updated.

Example: UPDATE Employee SET Mobile=9935467903 WHERE Emp_Name=โ€™Joeโ€™;

Get Siddhesh Kumbharโ€™s stories inย yourย inbox

Join Medium for free to get updates fromย thisย writer.

The SET statement is used in the above query to assign new values to a specific column, and the WHERE clause is used to select the rows for which the columns need to be modified. If we donโ€™t utilize the WHERE clause, all of the rowsโ€™ columns will be updated. As a result, the WHERE clause is utilized to select certain rows.

So, the example query will update the mobile number of the employee with name โ€˜Joeโ€™.

  • DELETE Command: In SQL, the DELETE statement is used to delete records from a table. Depending on the condition we set in the WHERE clause, we can delete a single record or numerous records.

Syntax: DELETE FROM table_name [WHERE condition];

Example: DELETE FROM Employee WHERE Emp_Name=โ€™Joeโ€™;

The above command will delete the record for employee with name โ€˜Joeโ€™ from โ€˜Employeeโ€™ table.

Data Control Language(DCL):

DCL (Data Controlling Language) is a query language that allows users to retrieve and edit data held in databases. The types of Data Controlling Language commands include Grant and Revoke.

  • GRANT Command: User access privileges to a database are given by this command. It can be used to grant SELECT, INSERT, UPDATE, and DELETE privileges to a user on a single table or several tables.

Syntax: GRANT SELECT, UPDATE ON MY_TABLE TO SOME_USER, ANOTHER_USER;

Example: GRANT INSERT, SELECT on accounts to Alex

Using this command, Alex has been granted permissions on accounts database objects like he can query or insert into accounts.

  • REVOKE Command: To take back permissions from the user REVOKE command is used. It is used to revoke a privilege (by default) or a specific command, such as UPDATE or DELETE, depending on the situation.

Syntax: REVOKE privilege_name ON object_name FROM {user_name |PUBLIC |role_name}

Example: REVOKE INSERT, SELECT on accounts from John

Using this command, the permissions of John like query or insert on accounts database objects has been removed.

Transaction Control Language(TCL):

Transaction Control Language (TCL) instructions are used in the database to manage transactions. This command is used to handle the DML statementsโ€™ modifications. TCL allows you to combine your statements into logical transactions.

Below mentioned are some of the TCL commands:

  • COMMIT Command: To save all the transactions in the database Commit is used.

Syntax: COMMIT;

Example: UPDATE Employee SET DOB=โ€™1995โ€“02โ€“17โ€™ WHERE Emp_Name=โ€™Joeโ€™;
COMMIT;
This example will insert the dob in the table which have name = Joe and then COMMIT the changes in the database.

  • ROLLBACK Command: All modifications must be canceled if any of the SQL grouped statements produce an error. The term โ€œrollbackโ€ refers to the process of undoing changes. This command can only be used to reverse transactions that have occurred since the last COMMIT or ROLLBACK command.

Syntax: ROLLBACK;

Example: UPDATE Employee SET DOB=โ€™1995โ€“02โ€“17โ€™ WHERE Emp_Name=โ€™Joeโ€™;
ROLLBACK;

This example would insert the dob in the table which have name = Joe and then ROLLBACK the changes in the database. Thus, this operation would not impact the table.

  • SAVEPOINT Command: Itโ€™s used to roll back a transaction to a specific point rather than the complete transaction.

Syntax: SAVEPOINT SavepointName;

Among all transactions, this command is exclusively used to create SAVEPOINT.
ROLLBACK is a command that is used to undo a set of transactions.

The syntax for rollback to savepoint command:
ROLLBACK TO SavepointName;

Example: SAVEPOINT S1; //savepoint created
DELETE FROM Employee WHERE Emp_Name = โ€˜Joeโ€™; //deleted
SAVEPOINT S2; //Savepoint created.

Data Query Language(DQL):

DQL statements are used to query the data contained in schema objects. The DQL Commands goal is to return a schema relation depending on the query supplied to it. DQL can be defined as follows: Itโ€™s a part of a SQL statement that lets you get data from a database and put it in order. The SELECT statement is included. This command allows you to extract data from a database in order to conduct actions on it. This is the same as the relational algebra projection operation. When a SELECT statement is executed on a table or set of tables, the result is compiled into a new temporary table, which is then displayed or received by the program, i.e. a front-end.

The database server examines the chosen clause, which is the first and one of the last clauses of the select statement. The reason for this is that we need to know all of the alternative columns that could be included in the final result set before we can decide what to include in it.

Syntax: SELECT expressions FROM Tables WHERE conditions;

Example: SELECT Emp_Name FROM Employee WHERE Mobile=9935467903;

The above command will select the record from the โ€˜Employeeโ€™ table where the mobile number is โ€˜9935467903โ€™.

Press enter or click to view image in full size
In this section, we will be discussing types of SQL commands. SQL Commands are divided into five broad categories โ€” DDL, DML, DCL, TCL, and DQL. Each category is further explained below:

๐’๐จ๐ฆ๐ž ๐จ๐Ÿ ๐“๐ก๐ž ๐Œ๐จ๐ฌ๐ญ ๐ˆ๐ฆ๐ฉ๐จ๐ซ๐ญ๐š๐ง๐ญ ๐’๐๐‹ ๐‚๐จ๐ฆ๐ฆ๐š๐ง๐๐ฌ ๐˜๐จ๐ฎ ๐๐ž๐ž๐ ๐“๐จ ๐Š๐ง๐จ๐ฐ ๐๐ž๐Ÿ๐จ๐ซ๐ž ๐’๐ญ๐š๐ซ๐ญ๐ข๐ง๐  ๐’๐๐‹:

SELECT โ€” extracts data from a database
UPDATE โ€” updates data in a database
DELETE โ€” deletes data from a database
INSERT INTO โ€” inserts new data into a database
CREATE DATABASE โ€” creates a new database
ALTER DATABASE โ€” modifies a database
CREATE TABLE โ€” creates a new table
ALTER TABLE โ€” modifies a table
DROP TABLE โ€” deletes a table
CREATE INDEX โ€” creates an index (search key)
DROP INDEX โ€” deletes an index

Credit โ€” Ankit Bansal !

Tagging W3Schools.com, DataLemur ๐Ÿ’ (Ace the SQL & Data Interview), GeeksForGeeks CIT Student Chapter & GeeksforGeeks for providing great Resources !

โœ…๐…๐จ๐ฅ๐ฅ๐จ๐ฐ Siddhesh Kumbhar ๐Ÿ“Œ

๐Ÿ””๐…๐จ๐ฅ๐ฅ๐จ๐ฐ on ๐Ÿ“ŒLinkedin : www.linkedin.com/in/siddhesh-kumbhar-517627b4
๐Ÿ””๐…๐จ๐ฅ๐ฅ๐จ๐ฐ on ๐Ÿ“ŒGitHub : https://github.com/siddheshk070

-๐Ÿ๐จ๐ซ ๐ฆ๐จ๐ซ๐ž ๐ฌ๐ฎ๐œ๐ก ๐š๐ฆ๐š๐ณ๐ข๐ง๐  ๐ง๐จ๐ญ๐ž๐ฌ ๐š๐ง๐ ๐œ๐จ๐ง๐ญ๐ž๐ง๐ญ๐ฌ.

#python #machinelearning #bigdata #deeplearning
#datascientist #datascience #dataanalytics #datascientist #dataanalyst #computerscience #pythonprogramming
#decisionintelligence #programming #coding #programmer
#datavisualization #analytics #data #digital #datavisualization #microsoft #powerbi #Tableau
#artificialintelligence #ai #technology #tech #git #github #Linkedin
#sql #sqlquery #mysql #sqlserver #sqldeveloper #sqlqueries #sqldatabase #dbms #databasemanagementsystem #database
#fresher #hiring #tier3 #notes #interview #project
#share #interviewpreparation #learning

--

--

Siddhesh Kumbhar
Siddhesh Kumbhar

Written by Siddhesh Kumbhar

Python ๐Ÿ| SQL ๐Ÿ“‚| Machine Learning ๐Ÿ”ข | Tableau ๐Ÿ“Š | Data Science ๐Ÿ’ป | Data Analyst ๐Ÿ“ฐ| Data Scientist | Mechanical Engineer | Data Science Engineer