Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL Truncate

Posted on 2013-11-15
6
Medium Priority
?
339 Views
Last Modified: 2013-11-21
I need to Truncate SQL database both MDB and LDB. How is this done and what are the risks?
I was told a full SQL backup should be done prior to performing this task.
Is there a way to determine when the last Full backup was done as well?
0
Comment
Question by:sullend
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 21

Expert Comment

by:oleggold
ID: 39651450
yes,db log , and yes,full backup required anyways before truncating
0
 

Author Comment

by:sullend
ID: 39651491
Do I have to detach in order to truncate?
0
 
LVL 2

Expert Comment

by:aheddell
ID: 39651542
No.  Won't work if you detach.

You can in theory truncate the log using the NO_LOG parameter on the BACKUP command.  Its easier to just to do the backup though.  

I assume this is a one off operation?  Is so, the easiest way to determine the last backup is in the SQL Server Management Studio, right-click on the database and select properties.  This data is held in the msdb..backupset table

Cheers

Alex
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 

Author Comment

by:sullend
ID: 39651600
Just found out the recovery model is SIMPLE, so BACKUP LOG will no work  At this point I just need a safe way to truncate the log file. Suggestions?  

Please be specific as possible I am not a SQL admin at any level...
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 39651672
You donĀ“t need to truncate the log file when your database is on SIMPLE recovery model, the file is always truncated
0
 
LVL 2

Accepted Solution

by:
aheddell earned 2000 total points
ID: 39656099
Do you mean you want to Shrink the file?  If so, you need to use DBCC SHRINKDATABASE or DBCC SHRINKFILE.  Or do it through the Management Studio
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ready to get certified? Check out some courses that help you prepare for third-party exams.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question