SlideShare ist ein Scribd-Unternehmen logo
1 von 16
BRIEF INSTRUCTION ABOUT MDF,LDF
By :
MD MASUM REZA
AGENDA OF THE DAY
 Introduction
 What is MDF , LDF and NDF
 Locating .mdf File .ldf file in server
 Role of MDF and LDF
 Restore data after truncating the
table(with example)
 Differential Backup
 Full Backup
 Conclusion
Introduction :-
The SQL Server provides the facility to restore your database
by attaching your .mdf file and .ldf file to the database.
We can directly Attach our existing .mdf and .ldf file to an SQL
instance by using SQL Server Management Studio or T-SQL.
We can restore our .mdf and .ldf file through execute some query.
What is MDF , LDF and NDF : -
MDF :–Stands for Master Database File. It contains all the main information of the
database that are part of the server. This extension also points to various other files. It
plays a crucial role in information storage. Overall it is very important for safe and secure
supervision of data. In case this file gets damaged, an MDF recovery procedure is
conducted to recover it. Doing so is important in order to save the data from going
missing.
NDF :-stand for Next Data File . NDF file is a user defined secondary database file of
Microsoft SQL Server with an extension .ndf, which store user data. Moreover, when
the size of the database file growing automatically from its specified size, you can use
.ndf file for extra storage and the .ndf file could be stored on a separate disk drive.
Every NDF file uses the same filename as its corresponding MDF file. We cannot open
an .ndf file in SQL Server Without attaching its associated .mdf file.
LDF :–Stand for LOG Database File .This file stores information related to transaction logs
for main data file. It basically keeps track of what all changes have been made in the
database. The information that this file stores ranges from date/time of change, details
of the changes made, as well as information related to whoever made the changes.
Information related to computer terminals where changes took place is also stored in the
logs.
Locating .mdf File .ldf file in server :-
Within each database, you will find two files namely MDF and LDF.
These two are basically file extensions used in Microsoft SQL. These files get automatically
created at the time of database creation. They also share the same storage location. The
reason why these files are so important is because they happen to be part of backup and
recovery process. In simpler words, in case something bad happens to the database, these are
the files the administrator will resort to for restoring and recovering the lost/damaged data.
Query can Execute:
 select * from sys.database_files
Role of MDF and LDF :-
 select * from fn_dblog (null , null)
Role of MDF and LDF
The primary purpose of an LDF file is to provide the ACID concept – Atomicity, Consistency,
Isolation, and Durability
Atomicity: if one part of the transaction fails, the entire transaction fails, and the database state is
left unchanged
Consistency: any transaction brings the database from one valid state to another
Isolation: the execution of concurrent transactions brings the database to a state as if the
transactions were executed serially, one by one
Durability: once committed, the transaction remain so, even in the case of errors, power loss, or
crashes
An LDF file stores enough information to replay or undo a change, or recover the database to a
specific point in time. Therefore, due to various auditing or recovery requirements, there is often a
need to open the LDF file and view its contents. But viewing LDF file content is not an easy task
Restore data after truncating the table :-
The below example will show how can retrieve data after truncate or delete if happen :
use master
1 .create database Test
go
USE Test
GO
CREATE TABLE Student
(
StudentID BIGINT IDENTITY PRIMARY KEY,
StudentName VARCHAR(128),
RollNo VARCHAR(10)
)
GO
INSERT INTO Student(StudentName , RollNo)
VALUES
('Reza','101')
,('Hari','102')
,('Sunil','103')
,('Naveen','104')
GO
Restore data after truncating the table :-
3. Take Database Backup :
BACKUP DATABASE Test
TO DISK = 'D:BackupNew folderMyTestDB.BAK'
GO
4. Truncate table student
5. select * from Student
2. select * from Student
Restore data after truncating the table :-
6. SELECT
[Current LSN],
Operation,
[Transaction ID],
[Begin Time],
[Transaction Name]
FROM
fn_dblog (NULL, NULL) where [Transaction Name] ='TRUNCATE TABLE‘
7. 00000021:0000005d:0001 take LSN (Log Sequence Numbers) from above code.
8. Convert LSN number from HEX to Decimal number. like below code
SELECT CAST (CONVERT (VARBINARY,'0x'+'00000021', 1) AS INT) as FirstPart, --33
CAST (CONVERT (VARBINARY,'0x'+'0000005d', 1) AS INT) as SecondPart, --93
CAST (CONVERT (VARBINARY,'0x'+'0001', 1) AS INT)as ThirdPart --1
GO
Restore data after truncating the table :-
9. Add preceding zeros for 93and 1.
 Note : no need for 33
 93=0000000093 (8 zeroes) total should be 10 digits
 1 =00001 (4 zeroes) total should be 5 digits.
 => 33000000009300001
 Now do following steps one by one .
BACKUP LOG Test
TO DISK = 'D:BackupNew folderMyTestDB.TRN'
GO
RESTORE DATABASE MyTestDB_Copy
FROM DISK = 'D:BackupNew folderMyTestDB.bak'
WITH
MOVE 'Test' TO 'D:BackupNew folderMyTestDB.mdf',
MOVE 'Test_log' TO 'D:BackupNew folderMyTestDB_log.ldf',
NORECOVERY
GO
Restore data after truncating the table :-
RESTORE LOG MyTestDB_Copy
FROM
DISK = N'D:BackupNew folderMyTestDB.TRN'
WITH
STOPBEFOREMARK = 'LSN:33000000009300001’
10 . use MyTestDB_Copy
select * from Student
Differential Backup:-
A differential backup is created similarly to a full backup, but with one important difference –
the differential backup only contains the data that has changed since the last full backup (the
active portion of the transaction log). Differential backups are cumulative not incremental. This
means that a differential backup contains all changes made since the last full backup, in spite of
the fact that they have already been included in previous differential backups. Differential backups
are created the following way:
How to Make a Differential Backup
To make a differential database backup simply add “WITH DIFFERENTIAL” clause:
BACKUP DATABASE your_database TO DISK = 'diff.bak' WITH DIFFERENTIAL
Full Backup :-
The simplest kind of SQL Server backup is a full database backup. It provides a complete copy of
the database but allows restoring the database only to a point-in-time when the backup was
made.Even if you add the “WITH STOPAT=<time or log sequence number>” option to restore
command you will not get the expected result because this option applies only when you restore
the transaction log. Please see how a periodic full backup works in the picture below:
How to Make a Full Backup
To make a full backup you can use T-SQL command:
BACKUP DATABASE your_database TO DISK = 'full.bak'
Another way to backup a database is to use
SQL Server Management Studio (SSMS):
right click on the database you want to backup, select “Tasks”, then “Back up…”.
Choose “Full” backup type, add a backup destination and click “OK”.
Conclusion
In the above section, we learned how to restore LDF and MDF files to a database. It
is highly recommended that you have to detach the MDF file before attaching a new
one. This is a very helpful method to restore database using MDF and LDF file.
1. https://sqljumble.blogspot.in/2016/11/how-to-recover-data-after-truncate.html
2. https://sqlbak.com/blog/recover-deleted-data-in-sql-server/
3. https://sqlbak.com/academy
Thanking You

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction of Database Design and Development
Introduction of Database Design and DevelopmentIntroduction of Database Design and Development
Introduction of Database Design and DevelopmentEr. Nawaraj Bhandari
 
Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)Rabin BK
 
Locks In Disributed Systems
Locks In Disributed SystemsLocks In Disributed Systems
Locks In Disributed Systemsmridul mishra
 
Introduction to distributed file systems
Introduction to distributed file systemsIntroduction to distributed file systems
Introduction to distributed file systemsViet-Trung TRAN
 
Backup and recovery in sql server database
Backup and recovery in sql server databaseBackup and recovery in sql server database
Backup and recovery in sql server databaseAnshu Maurya
 
SQL Server Database Backup and Restore Plan
SQL Server Database Backup and Restore PlanSQL Server Database Backup and Restore Plan
SQL Server Database Backup and Restore PlanHamid J. Fard
 
Storage Management - Lecture 8 - Introduction to Databases (1007156ANR)
Storage Management - Lecture 8 - Introduction to Databases (1007156ANR)Storage Management - Lecture 8 - Introduction to Databases (1007156ANR)
Storage Management - Lecture 8 - Introduction to Databases (1007156ANR)Beat Signer
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactionsNilu Desai
 
DATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALA
DATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALADATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALA
DATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALASaikiran Panjala
 
Hadoop Tutorial For Beginners | Apache Hadoop Tutorial For Beginners | Hadoop...
Hadoop Tutorial For Beginners | Apache Hadoop Tutorial For Beginners | Hadoop...Hadoop Tutorial For Beginners | Apache Hadoop Tutorial For Beginners | Hadoop...
Hadoop Tutorial For Beginners | Apache Hadoop Tutorial For Beginners | Hadoop...Simplilearn
 
Hadoop Architecture | HDFS Architecture | Hadoop Architecture Tutorial | HDFS...
Hadoop Architecture | HDFS Architecture | Hadoop Architecture Tutorial | HDFS...Hadoop Architecture | HDFS Architecture | Hadoop Architecture Tutorial | HDFS...
Hadoop Architecture | HDFS Architecture | Hadoop Architecture Tutorial | HDFS...Simplilearn
 
Case Study - SUN NFS
Case Study - SUN NFSCase Study - SUN NFS
Case Study - SUN NFSAshish KC
 
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...turgaysahtiyan
 
Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlAbDul ThaYyal
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed SystemsRupsee
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database conceptsTemesgenthanks
 

Was ist angesagt? (20)

Introduction of Database Design and Development
Introduction of Database Design and DevelopmentIntroduction of Database Design and Development
Introduction of Database Design and Development
 
Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)
 
Sql server basics
Sql server basicsSql server basics
Sql server basics
 
Multimedia Database
Multimedia DatabaseMultimedia Database
Multimedia Database
 
Locks In Disributed Systems
Locks In Disributed SystemsLocks In Disributed Systems
Locks In Disributed Systems
 
Introduction to distributed file systems
Introduction to distributed file systemsIntroduction to distributed file systems
Introduction to distributed file systems
 
Backup and recovery in sql server database
Backup and recovery in sql server databaseBackup and recovery in sql server database
Backup and recovery in sql server database
 
Parallel Database
Parallel DatabaseParallel Database
Parallel Database
 
SQL Server Database Backup and Restore Plan
SQL Server Database Backup and Restore PlanSQL Server Database Backup and Restore Plan
SQL Server Database Backup and Restore Plan
 
Storage Management - Lecture 8 - Introduction to Databases (1007156ANR)
Storage Management - Lecture 8 - Introduction to Databases (1007156ANR)Storage Management - Lecture 8 - Introduction to Databases (1007156ANR)
Storage Management - Lecture 8 - Introduction to Databases (1007156ANR)
 
management of distributed transactions
management of distributed transactionsmanagement of distributed transactions
management of distributed transactions
 
DATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALA
DATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALADATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALA
DATA WAREHOUSE IMPLEMENTATION BY SAIKIRAN PANJALA
 
Hadoop Tutorial For Beginners | Apache Hadoop Tutorial For Beginners | Hadoop...
Hadoop Tutorial For Beginners | Apache Hadoop Tutorial For Beginners | Hadoop...Hadoop Tutorial For Beginners | Apache Hadoop Tutorial For Beginners | Hadoop...
Hadoop Tutorial For Beginners | Apache Hadoop Tutorial For Beginners | Hadoop...
 
Hadoop Architecture | HDFS Architecture | Hadoop Architecture Tutorial | HDFS...
Hadoop Architecture | HDFS Architecture | Hadoop Architecture Tutorial | HDFS...Hadoop Architecture | HDFS Architecture | Hadoop Architecture Tutorial | HDFS...
Hadoop Architecture | HDFS Architecture | Hadoop Architecture Tutorial | HDFS...
 
Case Study - SUN NFS
Case Study - SUN NFSCase Study - SUN NFS
Case Study - SUN NFS
 
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
High Availability & Disaster Recovery with SQL Server 2012 AlwaysOn Availabil...
 
SQLServer Database Structures
SQLServer Database Structures SQLServer Database Structures
SQLServer Database Structures
 
Chapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency controlChapter 12 transactions and concurrency control
Chapter 12 transactions and concurrency control
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 
Object oriented database concepts
Object oriented database conceptsObject oriented database concepts
Object oriented database concepts
 

Ähnlich wie MDF and LDF in SQL Server

Db2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallsDb2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallssam2sung2
 
The best ETL questions in a nut shell
The best ETL questions in a nut shellThe best ETL questions in a nut shell
The best ETL questions in a nut shellSrinimf-Slides
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recoverysdrhr
 
SQL Repair Tool.
SQL Repair Tool.SQL Repair Tool.
SQL Repair Tool.SysCurve
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architectureAjeet Singh
 
data stage-material
data stage-materialdata stage-material
data stage-materialRajesh Kv
 
Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2nesmaddy
 
Sql server lesson10
Sql server lesson10Sql server lesson10
Sql server lesson10Ala Qunaibi
 
Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)
Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)
Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)Massimo Cenci
 
Standby db creation commands
Standby db creation commandsStandby db creation commands
Standby db creation commandsPiyush Kumar
 
Managing SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAManaging SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAConcentrated Technology
 
ELT Publishing Tool Overview V3_Jeff
ELT Publishing Tool Overview V3_JeffELT Publishing Tool Overview V3_Jeff
ELT Publishing Tool Overview V3_JeffJeff McQuigg
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3Ala Qunaibi
 
Db2 Important questions to read
Db2 Important questions to readDb2 Important questions to read
Db2 Important questions to readPrasanth Dusi
 
The best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherThe best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherSrinimf-Slides
 

Ähnlich wie MDF and LDF in SQL Server (20)

Db2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallsDb2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfalls
 
The best ETL questions in a nut shell
The best ETL questions in a nut shellThe best ETL questions in a nut shell
The best ETL questions in a nut shell
 
database.ppt
database.pptdatabase.ppt
database.ppt
 
database backup and recovery
database backup and recoverydatabase backup and recovery
database backup and recovery
 
SQL Repair Tool.
SQL Repair Tool.SQL Repair Tool.
SQL Repair Tool.
 
oracle dba
oracle dbaoracle dba
oracle dba
 
Oracle tutorial
Oracle tutorialOracle tutorial
Oracle tutorial
 
Ms sql server architecture
Ms sql server architectureMs sql server architecture
Ms sql server architecture
 
data stage-material
data stage-materialdata stage-material
data stage-material
 
Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2Steps for upgrading the database to 10g release 2
Steps for upgrading the database to 10g release 2
 
Sql server lesson10
Sql server lesson10Sql server lesson10
Sql server lesson10
 
Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)
Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)
Recipe 14 - Build a Staging Area for an Oracle Data Warehouse (2)
 
Standby db creation commands
Standby db creation commandsStandby db creation commands
Standby db creation commands
 
Managing SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAManaging SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBA
 
ELT Publishing Tool Overview V3_Jeff
ELT Publishing Tool Overview V3_JeffELT Publishing Tool Overview V3_Jeff
ELT Publishing Tool Overview V3_Jeff
 
Sql server lesson3
Sql server lesson3Sql server lesson3
Sql server lesson3
 
Db2 Important questions to read
Db2 Important questions to readDb2 Important questions to read
Db2 Important questions to read
 
Oracle11g notes
Oracle11g notesOracle11g notes
Oracle11g notes
 
The best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresherThe best Teradata RDBMS introduction a quick refresher
The best Teradata RDBMS introduction a quick refresher
 
Sqllite
SqlliteSqllite
Sqllite
 

Kürzlich hochgeladen

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 

Kürzlich hochgeladen (20)

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 

MDF and LDF in SQL Server

  • 1. BRIEF INSTRUCTION ABOUT MDF,LDF By : MD MASUM REZA
  • 2. AGENDA OF THE DAY  Introduction  What is MDF , LDF and NDF  Locating .mdf File .ldf file in server  Role of MDF and LDF  Restore data after truncating the table(with example)  Differential Backup  Full Backup  Conclusion
  • 3. Introduction :- The SQL Server provides the facility to restore your database by attaching your .mdf file and .ldf file to the database. We can directly Attach our existing .mdf and .ldf file to an SQL instance by using SQL Server Management Studio or T-SQL. We can restore our .mdf and .ldf file through execute some query.
  • 4. What is MDF , LDF and NDF : - MDF :–Stands for Master Database File. It contains all the main information of the database that are part of the server. This extension also points to various other files. It plays a crucial role in information storage. Overall it is very important for safe and secure supervision of data. In case this file gets damaged, an MDF recovery procedure is conducted to recover it. Doing so is important in order to save the data from going missing. NDF :-stand for Next Data File . NDF file is a user defined secondary database file of Microsoft SQL Server with an extension .ndf, which store user data. Moreover, when the size of the database file growing automatically from its specified size, you can use .ndf file for extra storage and the .ndf file could be stored on a separate disk drive. Every NDF file uses the same filename as its corresponding MDF file. We cannot open an .ndf file in SQL Server Without attaching its associated .mdf file. LDF :–Stand for LOG Database File .This file stores information related to transaction logs for main data file. It basically keeps track of what all changes have been made in the database. The information that this file stores ranges from date/time of change, details of the changes made, as well as information related to whoever made the changes. Information related to computer terminals where changes took place is also stored in the logs.
  • 5. Locating .mdf File .ldf file in server :- Within each database, you will find two files namely MDF and LDF. These two are basically file extensions used in Microsoft SQL. These files get automatically created at the time of database creation. They also share the same storage location. The reason why these files are so important is because they happen to be part of backup and recovery process. In simpler words, in case something bad happens to the database, these are the files the administrator will resort to for restoring and recovering the lost/damaged data. Query can Execute:  select * from sys.database_files
  • 6. Role of MDF and LDF :-  select * from fn_dblog (null , null)
  • 7. Role of MDF and LDF The primary purpose of an LDF file is to provide the ACID concept – Atomicity, Consistency, Isolation, and Durability Atomicity: if one part of the transaction fails, the entire transaction fails, and the database state is left unchanged Consistency: any transaction brings the database from one valid state to another Isolation: the execution of concurrent transactions brings the database to a state as if the transactions were executed serially, one by one Durability: once committed, the transaction remain so, even in the case of errors, power loss, or crashes An LDF file stores enough information to replay or undo a change, or recover the database to a specific point in time. Therefore, due to various auditing or recovery requirements, there is often a need to open the LDF file and view its contents. But viewing LDF file content is not an easy task
  • 8. Restore data after truncating the table :- The below example will show how can retrieve data after truncate or delete if happen : use master 1 .create database Test go USE Test GO CREATE TABLE Student ( StudentID BIGINT IDENTITY PRIMARY KEY, StudentName VARCHAR(128), RollNo VARCHAR(10) ) GO INSERT INTO Student(StudentName , RollNo) VALUES ('Reza','101') ,('Hari','102') ,('Sunil','103') ,('Naveen','104') GO
  • 9. Restore data after truncating the table :- 3. Take Database Backup : BACKUP DATABASE Test TO DISK = 'D:BackupNew folderMyTestDB.BAK' GO 4. Truncate table student 5. select * from Student 2. select * from Student
  • 10. Restore data after truncating the table :- 6. SELECT [Current LSN], Operation, [Transaction ID], [Begin Time], [Transaction Name] FROM fn_dblog (NULL, NULL) where [Transaction Name] ='TRUNCATE TABLE‘ 7. 00000021:0000005d:0001 take LSN (Log Sequence Numbers) from above code. 8. Convert LSN number from HEX to Decimal number. like below code SELECT CAST (CONVERT (VARBINARY,'0x'+'00000021', 1) AS INT) as FirstPart, --33 CAST (CONVERT (VARBINARY,'0x'+'0000005d', 1) AS INT) as SecondPart, --93 CAST (CONVERT (VARBINARY,'0x'+'0001', 1) AS INT)as ThirdPart --1 GO
  • 11. Restore data after truncating the table :- 9. Add preceding zeros for 93and 1.  Note : no need for 33  93=0000000093 (8 zeroes) total should be 10 digits  1 =00001 (4 zeroes) total should be 5 digits.  => 33000000009300001  Now do following steps one by one . BACKUP LOG Test TO DISK = 'D:BackupNew folderMyTestDB.TRN' GO RESTORE DATABASE MyTestDB_Copy FROM DISK = 'D:BackupNew folderMyTestDB.bak' WITH MOVE 'Test' TO 'D:BackupNew folderMyTestDB.mdf', MOVE 'Test_log' TO 'D:BackupNew folderMyTestDB_log.ldf', NORECOVERY GO
  • 12. Restore data after truncating the table :- RESTORE LOG MyTestDB_Copy FROM DISK = N'D:BackupNew folderMyTestDB.TRN' WITH STOPBEFOREMARK = 'LSN:33000000009300001’ 10 . use MyTestDB_Copy select * from Student
  • 13. Differential Backup:- A differential backup is created similarly to a full backup, but with one important difference – the differential backup only contains the data that has changed since the last full backup (the active portion of the transaction log). Differential backups are cumulative not incremental. This means that a differential backup contains all changes made since the last full backup, in spite of the fact that they have already been included in previous differential backups. Differential backups are created the following way: How to Make a Differential Backup To make a differential database backup simply add “WITH DIFFERENTIAL” clause: BACKUP DATABASE your_database TO DISK = 'diff.bak' WITH DIFFERENTIAL
  • 14. Full Backup :- The simplest kind of SQL Server backup is a full database backup. It provides a complete copy of the database but allows restoring the database only to a point-in-time when the backup was made.Even if you add the “WITH STOPAT=<time or log sequence number>” option to restore command you will not get the expected result because this option applies only when you restore the transaction log. Please see how a periodic full backup works in the picture below: How to Make a Full Backup To make a full backup you can use T-SQL command: BACKUP DATABASE your_database TO DISK = 'full.bak' Another way to backup a database is to use SQL Server Management Studio (SSMS): right click on the database you want to backup, select “Tasks”, then “Back up…”. Choose “Full” backup type, add a backup destination and click “OK”.
  • 15. Conclusion In the above section, we learned how to restore LDF and MDF files to a database. It is highly recommended that you have to detach the MDF file before attaching a new one. This is a very helpful method to restore database using MDF and LDF file. 1. https://sqljumble.blogspot.in/2016/11/how-to-recover-data-after-truncate.html 2. https://sqlbak.com/blog/recover-deleted-data-in-sql-server/ 3. https://sqlbak.com/academy