<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Apeksha Ekhande on Medium]]></title>
        <description><![CDATA[Stories by Apeksha Ekhande on Medium]]></description>
        <link>https://medium.com/@apekshaekhande001?source=rss-c4639030d29------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dqdLEGW137lqFM4xIzVnrw.jpeg</url>
            <title>Stories by Apeksha Ekhande on Medium</title>
            <link>https://medium.com/@apekshaekhande001?source=rss-c4639030d29------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 22:50:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@apekshaekhande001/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[All About SQL Constraints]]></title>
            <link>https://medium.com/@apekshaekhande001/all-about-sql-constraints-e7f50774ef54?source=rss-c4639030d29------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7f50774ef54</guid>
            <dc:creator><![CDATA[Apeksha Ekhande]]></dc:creator>
            <pubDate>Tue, 21 Mar 2023 23:45:07 GMT</pubDate>
            <atom:updated>2023-03-22T18:40:01.475Z</atom:updated>
            <content:encoded><![CDATA[<h4>Creating Foolproof Databases</h4><p>constraints basically the rules that are imposed on the data stored in a database table to ensure that the data meets certain criteria or conditions.</p><p>Constraints can be used to enforce various rules, such as ensuring that a column cannot have a NULL value, or that each value in a column is unique. Constraints can also be used to enforce referential integrity, where the data in one table is related to the data in another table.</p><p>By enforcing constraints, database administrators can ensure the accuracy, consistency, and integrity of the data in a database. Constraints help prevent data from being entered incorrectly or inconsistently, which can lead to data corruption or errors in the database.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k_3ZaYImKApLD-yH" /><figcaption>Photo by <a href="https://unsplash.com/@anagani_saikiran?utm_source=medium&amp;utm_medium=referral">Sai Kiran Anagani</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Types of SQL constraints:-</p><p><strong>A) DOMAIN CONSTRAINTS :-</strong></p><ol><li><strong>NOT NULL</strong></li><li><strong>UNIQUE</strong></li><li><strong>DEFAULT</strong></li><li><strong>CHECK</strong></li><li><strong>ENUM</strong></li></ol><p><strong>B)KEY CONSTRAINTS</strong></p><ol><li><strong>PRIMARY KEY</strong></li><li><strong>FOREIGN KEY</strong></li></ol><p>Let’s understand all these constraints with example of “CLASS ” table</p><pre>CREATE TABLE CLASS(<br>ID INT,<br>NAME VARCHAR(255),<br>AGE INT,<br>GENDER CHAR(1),<br>SUBJECT VARCHAR(255)<br>);<br>INSERT INTO CLASS VALUES (1,&quot;PRIYA&quot;,20,&quot;F&quot;,&quot;MATHS&quot;);<br>INSERT INTO CLASS VALUES (2,&quot;NEHA&quot;,22,&quot;F&quot;,&quot;SCIENCE&quot;);<br>INSERT INTO CLASS VALUES (3,&quot;KIRAN&quot;,21,&quot;M&quot;,&quot;HISTORY&quot;);<br>SELECT * FROM CLASS;</pre><p>Output-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*7ZK2Nub9WUbcegh6uIulZw.png" /></figure><p>above table doesn&#39;t contains any constraint so if we insert null values, repeated ID table will accept that so, for stopping all these actions we need to put constrains while creating a table.</p><pre>CREATE TABLE CLASS(<br>ID INT UNIQUE NOT NULL,<br>NAME VARCHAR(255) NOT NULL,<br>AGE INT CHECK(AGE&gt;16),<br>GENDER ENUM(&quot;M&quot;,&quot;F&quot;),<br>MARKS DEFAULT(20)<br>SUBJECT VARCHAR(255) NOT NULL<br>);<br>INSERT INTO CLASS VALUES (1,&quot;PRIYA&quot;,20,50,&quot;MATHS&quot;);<br>INSERT INTO CLASS VALUES (2,&quot;NEHA&quot;,22,60,&quot;SCIENCE&quot;);<br>INSERT INTO CLASS VALUES (3,&quot;KIRAN&quot;,21,70,&quot;HISTORY&quot;);<br>SELECT * FROM CLASS;</pre><p>The best practice is that to add all that constraints which we want to add it while creating the table. if incase it’s not there we can add later also by using <strong>ALTER </strong>command.</p><p><strong>NOT NULL -</strong></p><p>In SQL, the NOT NULL constraint is used to ensure that a column cannot contain a NULL value. When a column is defined with the NOT NULL constraint, it means that every row in the table must have a value for that column. Here&#39;s an example of how to do it:</p><pre>ALTER TABLE table_name<br>ALTER COLUMN column_name SET NOT NULL;</pre><p>For example, let’s say we have a table called “CLASS” with columns for “NAME”, If we want to ensure that the “NAME” column always contains a value, we can define it with the NOT NULL constraint as follows:</p><pre>ALTER TABLE CLASS<br>ALTER COLUMN NAME SET NOT NULL;</pre><p><strong>UNIQUE —</strong></p><p>A unique constraint is used to ensure that the values in a column or a combination of columns are unique across all the rows in a table. This means that none of two rows can have the same combination of values in the specified columns ,here is the code for that:</p><pre>ALTER TABLE table_name<br>ADD CONSTRAINT constraint_name UNIQUE (column_name);</pre><p>For example, let’s say we have a table called “CLASS” with columns for “ID. If we want to add a unique constraint to the “ID” column to ensure that none of two students have Same ID ,we can use the following SQL query:</p><pre>ALTER TABLE  CLASS<br>ADD CONSTRAINT ID UNIQUE (ID);</pre><p><strong>DEFAULT —</strong></p><p>If a value is not clearly specified for a column, a default constraint for that column specifies a default value that will be inserted into the column for any new rows that are added to the table. below we can see the query for default constraint</p><pre>ALTER TABLE products ALTER COLUMN price SET DEFAULT 0;</pre><p>For example, if you want to change the default value for the “MARKS” column to 20 ,means we want at least 20 marks in each row . if we not entered any value into marks column still it shows 20 . We could use the following statement:</p><pre>ALTER TABLE CLASS ALTER COLUMN MARKS SET DEFAULT 20;</pre><p><strong>CHECK —</strong></p><p>A CHECK constraint is used to ensure that the values in a column meet a specified condition or range of values. This means that any row inserted into a table must meet the condition specified in the CHECK constraint.</p><pre>ALTER TABLE table_name<br>ADD CONSTRAINT constraint_name CHECK (condition);</pre><ul><li>table_name: the name of the table we want to add the CHECK constraint to.</li><li>constraint_name: the name we want to give to the constraint (optional).</li><li>condition: the condition that the values in the column must meet in order to satisfy the constraint.</li></ul><p>For example, let’s say you have a table called “CLASS” with columns for “AGE” If you want to add a CHECK constraint to the &quot;AGE&quot; column to ensure that no student has age below 16 then we can use the following SQL statement:</p><pre>ALTER TABLE CLASS<br>ADD CONSTRAINT  AGE CHECK(AGE&gt;16);</pre><p><strong>ENUM —</strong></p><p>ENUM Constraint works like True or False means if we applied it to a column ,it will allow only those values which we listed in ENUM . you can use the following SQL statement for defining :</p><pre>ALTER TABLE table_name MODIFY COLUMN column_name ENUM(values or letters)</pre><ul><li>mention_characters: add values and character which we want to specify in column.</li></ul><p>For example, let’s say we have a table called “students” with a column called “gender” which is defined as ENUM(“M”,“F”). To add a constraint to ensure that only these two values can be inserted into the column, you can use the following SQL query:</p><pre>ALTER TABLE CLASS MODIFY COLUMN GENDER ENUM(&quot;M&quot;,&quot;F&quot;);</pre><p><strong>B) KEY CONSTRAINTS-</strong></p><ol><li><strong>PRIMARY KEY — — </strong>Primary key constraint basically a combination of a unique constraint and a not-null constraint. we can’t add duplicate value and null value into the column which contains primary key. it’s basically use for ID or Roll call. We can check row number by primary key column. We can add primary key after creating the table but it affects to the existing data. if our existing column contains duplicate or null value the alter command will show an error. means the best practice for using primary key is use it while creating a table.</li></ol><p>let’s create a table with a primary key</p><pre>CREATE TABLE COMPANY( <br>EMP_ID INT PRIMARY KEY,<br>NAME VARCHAR(255),<br>AGE INT);<br><br>INSERT INTO COMPANY VALUES (101,&quot;PRIYA&quot;,30);<br>INSERT INTO COMPANY VALUES (102,&quot;RAJ&quot;,25);<br>INSERT INTO COMPANY VALUES (104,&quot;NEETA&quot;,27);<br>INSERT INTO COMPANY VALUES (104,&quot;SNEHAL&quot;,26);</pre><p>In the above example I have entered duplicate EMP_ID (emp_id=104). If we run the above query it will show an error and it will accept 104 only one time. you can see table below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*lv6XwLA9JPQUTGyX0Y6AxQ.png" /></figure><p><strong>2. FOREIGN KEY —</strong></p><p>A field or set of fields in a database table that refers to the primary key of another table is known as a foreign key. It creates a connection between two tables and makes it possible for data to be linked between them. Most of the times we need to create referential integrity between two tables and we can called them like parent table and is child table. parent table contains primary key while child table contain foreign key.</p><p>For example, if we have tow tables “COMPANY” and “EMPLOYEE”. The “EMPLOYEE” table might have a foreign key called “ID” which references the “EMP_ID” field in the “COMPANY” table. This would helps us to find related data in to another table .If we add a few columns in parent table we can only insert related data into the child table ,if we try to add data which reference is not in parent table child table (foreign key ) table will throw an error.</p><pre>CREATE TABLE EMPLOYEE( <br>ID INT ,<br>POSITION VARCHAR(255),<br>SALARY INT ,<br>FOREIGN KEY (ID) REFERENCES COMPANY(EMP_ID)<br>);<br>INSERT INTO customer VALUES (101,&quot;Pune&quot;,1);<br>INSERT INTO customer VALUES (102,&quot;Mumbai&quot;,3);<br>INSERT INTO customer VALUES (103,&quot;Nashik&quot;,2);</pre><p>Output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*LBCm4FlHpJx9K66Zrmfvhg.png" /></figure><p>In the above example we have entered different ID (103) which not present in company table so database shows an error “Foreign key constraint fails”. means first we need to update ID (103) in the Primary key table (parent table) and after that we could insert values related to ID 103 in Foreign key table (child table).</p><p>This is all about SQL constraints ,Thanks for reading my Article…hope it helps you .</p><blockquote><a href="https://github.com/apekshaekhande/My-SQL-/blob/main/06-%20Constraints.sql">Click here to get SQL file of all these constraints 👈</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7f50774ef54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic SQL Commands]]></title>
            <link>https://medium.com/@apekshaekhande001/basic-sql-commands-a3a408bb64c2?source=rss-c4639030d29------2</link>
            <guid isPermaLink="false">https://medium.com/p/a3a408bb64c2</guid>
            <category><![CDATA[sql-dml]]></category>
            <category><![CDATA[commands]]></category>
            <category><![CDATA[sql-command]]></category>
            <category><![CDATA[sql-tcl]]></category>
            <category><![CDATA[sql-ddl]]></category>
            <dc:creator><![CDATA[Apeksha Ekhande]]></dc:creator>
            <pubDate>Wed, 04 Jan 2023 16:46:03 GMT</pubDate>
            <atom:updated>2023-01-07T07:30:36.801Z</atom:updated>
            <content:encoded><![CDATA[<h4>SQL Commands</h4><h4>List of 5 Basic SQL Commands Understand With Simple Example.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G9U04DIMx6JNMZ4e" /><figcaption>Photo by <a href="https://unsplash.com/@christinhumephoto?utm_source=medium&amp;utm_medium=referral">Christin Hume</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, We are going to cover all these basic SQL commands that are building blocks of the database. I’ve discovered that it is far more difficult for people to memorize all these, especially those who are new to the field. so I explain it by using easy examples.</p><p>Structured Query Language or SQL, is a query language that is used in programming and designed for managing data in an RDBMS(Relational Database Management System). i.e. instructions needed to interface with a database in order to carry out operations, functions, and queries on data are known as SQL commands.</p><p>If you plan to work with SQL, you should be familiar with the following list of fundamental SQL Commands(also known as clauses).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*ObXtbvbtVwo9nNkPQEeZsg.png" /><figcaption>Mind Map for Basic SQL Commands</figcaption></figure><p>1. DDL</p><p>2. DML</p><p>3. DQL</p><p>4. DCL</p><p>5. TCL</p><p>Let’s talk briefly about all these commands and take a sip of these with a simple example.</p><h4><strong>What is DDL?</strong></h4><p><strong>Data Definition Language -</strong></p><p>DDL is an SQL basic Command that only deals with the structure of the table, not with data that is present in the table. we can memorize this by using an acronym called “Dr.Cat” (D-DROP, R-RENAME, C-CREATE, A-ALTER, T-TRUNCATE)</p><blockquote>Following are the commands that come under DDL</blockquote><blockquote>I)CREATE, II) ALTER, III) DROP, IV) RENAME , V) TRUNCATE</blockquote><p><strong>I) CREATE -</strong></p><p>The CREATE command is used for creating a Database and creating a new Table in a Database</p><p>Suppose We want to create a database called “S_DATA” And want to create a new table in it called “Student” we have to use the following query….</p><pre>CREATE DATABASE S_DATA;</pre><pre>CREATE TABLE Student(<br>ID INT, <br>NAME VARCHAR(255),<br>AGE INT,<br>CITY VARCHAR(255)<br>);</pre><p>Output- Here we can see that a new table “Student” has been created</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/375/1*CIxJbdB76l7FNwwYCEZwbw.png" /><figcaption>Create Student table</figcaption></figure><p><strong>II)</strong> <strong>ALTER -</strong></p><p>The ALTER command is used for various purposes like adding a new column or giving modifications to the existing table, in short, it can alter the table structure.</p><p><strong>&gt; Add New Column- </strong>Suppose we have a table called “Student” and want to add a new column called “MARKS” in it, we could use a query like this</p><pre>ALTER TABLE Student ADD COLUMN MARKS INTEGER DEFAULT 0;</pre><p>Output- Here we see that new column “Marks” has been added .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*nZg3K_Gffa72UAMREl-RIQ.png" /><figcaption>ALTER- Add Marks column</figcaption></figure><p>&gt; <strong>Delete Column- </strong>If we want to delete an existing column called “ CITY” from the table “Student” we use query like this</p><pre>ALTER TABLE Student DROP COLUMN CITY;</pre><p>Output- Here we can see that column “CITY” has been removed from table “Student”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*4lkdI_5_1v3rTuDG-L0dkw.png" /><figcaption>ALTER- Drop column CITY</figcaption></figure><p><strong>&gt;Rename Table- </strong>If we want to change the name of the Table “Student” to “Class”</p><pre>ALTER TABLE Student RENAME TO Class;</pre><p>Output- Here we can see that table “Student” has been renamed by “Class”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*YM11xaJLrTJM_m-0t75lqA.png" /><figcaption>ALTER- Rename Table as “Class”</figcaption></figure><p><strong>&gt; Modify Table</strong>- If we want to modify an existing column called “NAME Varchar(255)” to “NAME varchar (10)” we use query like this</p><pre>ALTER TABLE CLASS MODIFY COLUMN NAME VARCHAR (10);<br></pre><p>Output- we can check the datatype of columns by using DESCRIBE Command. in this we can see that the data type of the “NAME” column has been changed to varchar(10).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*Jh5s6ZKvnPuFX0lLucoCHA.png" /><figcaption>ALTER-Modified Class table</figcaption></figure><p><strong>III)</strong> <strong>DROP -</strong></p><p>The DROP command is used to drop a Database or a Table.</p><p>Suppose, We Want to Delete a table called “Class” we could use the query I mention below and we can delete the whole database also.</p><pre>Drop table Class;</pre><pre>Drop Database S_DATA;</pre><p><strong>IV) RENAME-</strong></p><p>The RENAME command is used to rename the column</p><p>Suppose, We want to Rename a column called “Class” to “My_Class”. For that, we need to run the simple query I mentioned below which works same as rename in ALTER command.</p><pre>RENAME TABLE CLASS TO My_Class;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*sIxu6UaT5cyP7KFAjnZ_3w.png" /><figcaption>Rename “Class “To “My_class”</figcaption></figure><p><strong>V) TRUNCATE-</strong></p><p>The TRUNCATE<strong> </strong>command removes the data from a table but leaves the table itself alive(This query works after DML command )</p><p>If we want a table structure again and again but we have to change records daily so what we can do? we could make this happen by using the TRUNCATE command.</p><p>By using following query all the records from “My_Class ”table would get removed but the structure of “My_Class” remains as it is.</p><pre>Truncate My_Class;</pre><p>Output- we can conclude here It simply remove all records from table “My_Class” but the structure of table remain as it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*9hP-HaBs53GFzI_wLDtBpA.png" /><figcaption>Truncate “My_class “</figcaption></figure><p><strong>What is DML?</strong></p><p><strong>Data Manipulation Language -</strong></p><p>DML is an SQL basic Command that deals with the Insertion, Updating, and Deletion of data.</p><blockquote>Following are the commands that come under DML</blockquote><blockquote>I)INSERT, II) UPDATE, III) DELETE</blockquote><p><strong>I) INSERT—</strong></p><p>The INSERT is a command or instruction we have to give a table for insert records into the table.</p><p>Suppose we have a table called “My_Class” and we want to insert a new record into it we have to go through the following query.</p><pre>INSERT INTO My_Class VALUES(1,&quot;Rani&quot;,18,89);<br>INSERT INTO My_Class VALUES(2,&quot;Ramesh&quot;,20,80);<br>INSERT INTO My_Class VALUES(3,&quot;Priya&quot;,24,78);<br>INSERT INTO My_Class VALUES(4,&quot;Joy&quot;,22,89);</pre><p>Output- Here we see that records has been added in table “My_Class”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/411/1*v1a0venxqUaYmfxA5ec3vw.png" /><figcaption>Insert Records into “My_class”</figcaption></figure><p><strong>II) UPDATE-</strong></p><p>The UPDATE command is used to update records that are already present in the table. before UPDATE and DELETE we need to set <strong>&lt;SET_SQL_SAFE_UPDATES=0&gt; </strong>it prevent user from updating and deleting records without a <strong>WHERE</strong> clause.</p><p>Let’s update a records from “My_Class” table by using following query.</p><pre>UPDATE My_Class<br>SET MARKS = 90<br>WHERE ID = 1;</pre><p>Output- So ,we can see that the marks has been updated for ID = 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/1*AZJzW6yeCZJfCqy-uxrFhA.png" /><figcaption>update “My_class “</figcaption></figure><p><strong>III) DELETE —</strong></p><p>The DELETE Command is used for deleting records from a table. DELETE command Remove the entire row which we mentioned in the WHERE clause.</p><p>Suppose we want to remove some records from a table “My_Class” we can use the query mentioned below.</p><pre>DELETE FROM My_class WHERE ID =3;</pre><p>Output- we can see that the record for ID =3 has been deleted from the table “My_Class”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*N4PEpcLQuc4q9PxlVXVrJA.png" /><figcaption>Delete Records</figcaption></figure><h4>What is DQL?</h4><p><strong>Data Query Language -</strong></p><p>The SELECT is the only command that comes under Data Query Language.</p><p><strong>SELECT -</strong></p><p>The<strong> </strong>SELECT command is used for the selection of rows from a table. We could use this query for only view purposes i.e. if we want to see data from a particular table we can use it. It doesn’t make any changes to the table.</p><p>Suppose we have a table called “My_Class” we can write a query to view data of it</p><pre>SELECT ID,NAME FROM My_class WHERE AGE=18;</pre><p>Output- Here we can see that only those row has been selected which we mentioned in where clause.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/433/1*nB2TXdazWGaBHUzLoTCpNw.png" /><figcaption>Select Records</figcaption></figure><p><strong>What is DCL?</strong></p><p><strong>Data Control Language -</strong></p><p>The DCL command is related to giving and taking permission related to Database.</p><blockquote>Following are the commands that come under the Data Control language.</blockquote><blockquote>I)GRANT ,II)REVOKE</blockquote><p><strong>I) GRANT-</strong></p><p>The GRANT command or instruction is used for giving permission from one user to another user.</p><pre>GRANT SELECT, UPDATE ON MY_Table TO One_USER, ANOTHER_USER;  </pre><p><strong>II)</strong> <strong>REVOKE –</strong></p><p>The REVOKE command or instruction is used to take back permission for the database from the user.</p><pre>REVOKE SELECT, UPDATE ON MY_Table FROM USER1, USER2;  </pre><p><strong>What is TCL?</strong></p><p><strong>Transaction Control Language -</strong></p><p>Here we going to discuss about Transaction Control Language. We all know that before using TCL commands we need to run <strong>&lt;START TRANSACTION&gt; </strong>command first. We couldn&#39;t use TCL command without start transaction else the changes you going to made into the table it will commit automatically and there is no another option to remove that changes without disturbing previous records. If we use <strong>&lt;START TRANSACTION&gt; </strong>and all <strong>TCL</strong> commands that I mention below we could make transaction process easy.</p><p>The Transaction Control Language commands are the commands that can only use with DML (Data manipulation language) commands like INSERT, DELETE and UPDATE. These operations are automatically committed in the database that’s why they cannot be used while creating tables or dropping them.</p><p>Here are the commands that come under the Transaction control language.</p><p><strong>1) SAVEPOINT- </strong>A user may deploy the UPDATE command to make a few changes in the Database , and after sometime they realise that some changes are have to do in database for that purpose we should use savepoint after every exicution in query. So, if, due to some reason, the inserted, updated, or deleted data is incorrect, the user can use the ROLLBACK command to roll back the data to the last committed state or any particular SAVEPOINT .</p><p>This command is used to temporarily save the data at a specific place so that it can be rolled back at any time.</p><p>We have previous table called “My_Class” we are going to INSERT new records into it ,UPDATE and DELETE some records from it and we&#39;ll give savepoint for every execution shown below .</p><pre>START TRANSACTION;<br>INSERT INTO  My_class VALUES (5,&quot;Krishna&quot;,22,79);<br>INSERT INTO  My_class VALUES (6,&quot;Merry&quot;,20,68);<br>SAVEPOINT S1;<br><br>UPDATE My_Class <br>SET NAME= &quot;Carry&quot;<br>WHERE ID=5;<br>SAVEPOINT S2;<br><br>DELETE FROM My_Class WHERE ID=4;<br>SAVEPOINT S3;</pre><p>Output- Here we can see that all transactions has been done step by step like</p><p>(i) Step 1- Two records has been inserted at savepoint <strong>S1</strong> (ii) Step2- one record has been Updated at savepoint <strong>S2 (</strong>iii) Step 3- one record has been Deleted at savepoint <strong>S3.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*0TPsz19QtHj6b-kLYI_oKQ.png" /><figcaption>Savepoint</figcaption></figure><p><strong>II)</strong> <strong>ROLLBACK —</strong></p><p>The ROLLBACK command allows us to roll back data to a specific savepoint or the last committed state if the inserted, updated, or deleted data is wrong for some reason. Using this command we can retrieve records or return it to its most recent commit or savepoint state.</p><p>Suppose, By mistake we deleted wrong ID like we shouldn’t want to delete ID=4 from table “My_class” so we can undo that step . we just have to ROLLBACK to its previous savepoint</p><pre>Rollback to S2;</pre><p>Output- Here we can see that after rollback to S2 all that queries get undo till Savepoint S2 i.e. ID=4 has been rollback in table My_Class .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/464/1*g7dSNHy1SEQ2378et3jBCA.png" /></figure><p>III) <strong>COMMIT </strong>—</p><p>This command enables a user to permanently store a certain transaction in the database. The changes during using a DML command like DELETE, UPDATE, or INSERT are temporary until the current session is ended. So We can use the COMMIT command to save changes permanently. i.e. you can undo the changes if the user didn’t commit using the COMMIT command.</p><p>We can use the COMMIT command after INSERT, UPDATE, and DELETE as shown below.</p><p>If we want to save all our execution and want to stop transaction we could write simple query .</p><pre>COMMIT;</pre><p>This is all about basic SQL commands ,Thanks for reading my Article…hope it helps you .</p><blockquote><a href="https://github.com/apekshaekhande/My-SQL-/blob/main/Basic%20SQL%20Commands.sql">click here to get .sql file of all these commands </a>👈</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a3a408bb64c2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>