SQL stands for Structured Query Language. A query language is a kind of programming language that's designed to facilitate retrieving specific information from databases, and that's exactly what SQL does.
An operator is a reserved word or a character used primarily in an SQL statement's WHERE clause to perform operation(s), such as comparisons and arithmetic operations.
SQL commands are the instructions used to communicate with a database to perform tasks, functions, and queries with data. SQL commands can be used to search the database and to do other functions like creating tables, adding data to tables, modifying data, and dropping tables
MySQL queries are SQL functions that help us to access a particular set of records from a database table. We can request any information or data from the database using the clauses or let’s say SQL statements.
A query is a question or inquiry to a set of data. We use SQL, or Structured Query Language, to retrieve data from databases. When we build the structure we are pulling data from tables and fields. The fields are columns in the database table while the actual data makes up the rows.
An SQL key is either a single column (or attribute) or a group of columns that can uniquely identify rows (or tuples) in a table. SQL keys ensure that there are no rows with duplicate information.
Joins in SQL can be of four different types, subjected to the outcome expected by combining records from two or more tables by making use of the common columns from tables involved in the Join function. Inner Join is used to get records with same values In both tables, Left Join is used to get all records from Left side table and only matching values from right table and Right Join is used to get all records from Right table and only matching records in left table. finally Full Join to get all the records from both tables irrespective of matching records.
CONGRATULATION YOU HAVE COMPLETED THIS COURSES IF YOU STUDY AT THIS POINT. CHECK OUT OUR INDUSTRY RECOGNIZED CERTIFICATION COURSES
0
How To Recover Deleted Rows In SQL Server
Note – All screenshots are applied to SQL Server 2012 Enterprise Evaluation Edition.
Introduction
We can recover deleted rows if we know the time when data is deleted We can achieve this goal using LSN ( Log Sequence Numbers ). As per Microsoft, “Every record in the SQL Server transaction log is uniquely identified by a log sequence number (LSN)”. We will use these LSNs to recover our deleted data.
Recover Deleted Rows from SQL Server Table
To recover deleted rows from the table in database, database must be FULL Recovery or BULK-LOGGED Recovery Model.
SIMPLE Recovery doesn’t support transaction logs backup hence it is not possible in SIMPLE recovery model.
Steps Involved
Let’s set up environment for recovering deleted rows step by step:
Step 1
Create a database name RecoverDeletedData and set recovery model as FULL if it is not set as FULL.
In Step 12, we will apply transaction log to restore deleted rows using LSN “00000025:000001d0:0001”
USE RecoverDeletedData
GO
RESTORE LOG RecoverDeletedData_COPY
FROM DISK = N‘D:\RecoverDeletedData\RDOTrLog.trn’
WITH STOPBEFOREMARK = ‘lsn:0x00000025:000001d0:0001′
Figure 9 – Restoring transaction log using LSN
Here one thing we need to remember that the LSN values are in hexadecimal form and for restoring with LSN value we need it in decimal form. To convert it to decimal form just put 0x before LSN like below in stopbeforemark clause
STOPBEFOREMARK = ‘lsn:0x00000025:000001d0:0001′
Step 13
As in above screenshot restore operation successfully completed, so here we check that our deleted records are back in RecoverDeletedData_Copy Database:
USE RecoverDeletedData_Copy
GO
Select * from friends
Figure 10 – Fetching records from RecoverDeletedData_Copy database
Wow!! We got all records back…
In this way we can recover deleted records for any database provided database is in FULL or BULK-LOGGED Recovery model.
Final Words
So from the above explanation and steps it is very clear that how we can recover deleted rows if we deleted it accidentally. But before that we must have idea about LSNs, transaction logs etc.