๐๐๐ ๐๐จ๐ฆ๐ฆ๐๐ง๐๐ฌ.
๐บ๐ธ๐ณ ๐๐ ๐ ๐๐๐๐๐ ๐๐๐ ๐๐๐๐๐๐๐๐ ๐๐๐ ๐๐๐๐๐๐๐, ๐๐๐๐๐๐๐๐๐๐๐๐ ๐๐๐ ๐๐๐๐๐๐๐๐๐๐ ๐ ๐๐๐ ๐๐ ๐ ๐๐๐๐๐๐๐๐.
๐บ๐๐๐๐๐๐๐๐๐ ๐ธ๐๐๐๐ ๐ณ๐๐๐๐๐๐๐(๐บ๐ธ๐ณ) ๐๐ ๐๐ ๐๐๐ ๐๐๐๐ ๐๐ ๐๐๐ ๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐ ๐๐ ๐๐๐ ๐๐๐ ๐๐ ๐๐๐๐๐ ๐๐ ๐๐๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐๐๐๐ ๐๐ ๐๐๐ ๐๐๐๐๐๐๐๐ ๐ ๐๐๐๐๐๐๐ ๐๐๐ ๐๐๐๐ ๐๐ ๐๐๐ ๐๐๐ ๐๐๐๐ ๐๐๐๐๐๐๐๐ ๐๐ ๐๐๐๐๐๐ ๐ ๐ ๐๐๐๐๐๐๐. ๐บ๐ธ๐ณ ๐๐๐๐ ๐๐๐๐๐๐๐ ๐๐๐๐๐๐๐ ๐ ๐๐๐๐ ๐ช๐๐๐๐๐, ๐ซ๐๐๐, ๐ฐ๐๐๐๐๐, ๐๐๐. ๐๐ ๐๐๐๐๐ ๐๐๐ ๐๐๐ ๐๐๐๐๐๐๐๐ ๐๐๐๐๐.
๐๐ก๐๐ฌ๐ ๐๐๐ ๐๐จ๐ฆ๐ฆ๐๐ง๐๐ฌ ๐๐ซ๐ ๐ฆ๐๐ข๐ง๐ฅ๐ฒ ๐๐๐ญ๐๐ ๐จ๐ซ๐ข๐ณ๐๐ ๐ข๐ง๐ญ๐จ ๐๐ข๐ฏ๐ ๐๐๐ญ๐๐ ๐จ๐ซ๐ข๐๐ฌ ๐๐ฌ:
- ๐๐๐ โ ๐๐๐ญ๐ ๐๐๐๐ข๐ง๐ข๐ญ๐ข๐จ๐ง ๐๐๐ง๐ ๐ฎ๐๐ ๐
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โ.
๐๐จ๐ฆ๐ ๐จ๐ ๐๐ก๐ ๐๐จ๐ฌ๐ญ ๐๐ฆ๐ฉ๐จ๐ซ๐ญ๐๐ง๐ญ ๐๐๐ ๐๐จ๐ฆ๐ฆ๐๐ง๐๐ฌ ๐๐จ๐ฎ ๐๐๐๐ ๐๐จ ๐๐ง๐จ๐ฐ ๐๐๐๐จ๐ซ๐ ๐๐ญ๐๐ซ๐ญ๐ข๐ง๐ ๐๐๐:
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 ๐
-๐๐จ๐ซ ๐ฆ๐จ๐ซ๐ ๐ฌ๐ฎ๐๐ก ๐๐ฆ๐๐ณ๐ข๐ง๐ ๐ง๐จ๐ญ๐๐ฌ ๐๐ง๐ ๐๐จ๐ง๐ญ๐๐ง๐ญ๐ฌ.
#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







