简体   繁体   English

如何减少SQL Server 2014数据库的大小

[英]How to decrease size of SQL Server 2014 database

I have a SQL Server 2014 database dump which is approx. 我有一个大约的SQL Server 2014数据库转储。 60GB large. 60GB大。 In SQL Server Management Studio, it is shown for the original DB, that the "ROWS Data" has an initial size of ~ 99000MB and the "LOG" has an initial size of ~ 25600MB. 对于原始数据库,在SQL Server Management Studio中显示,“ ROWS数据”的初始大小约为99000MB,而“ LOG”的初始大小约为25600MB。

Now there are a view tables in the Database which are about 10GB large and which I can flush/clean. 现在数据库中有一个大约10GB的视图表,我可以对其进行冲洗/清洁。

After deleting the data inside those tables, what is the best way to decrease the physical size of the database? 删除这些表中的数据后,减小数据库物理大小的最佳方法是什么? A lot of posts I discovered are dealing with SHRINKDATABASE but some articles won't recommend it because of bad fragmentation and performance. 我发现很多帖子都是关于SHRINKDATABASE的,但是由于碎片和性能不好,一些文章不推荐它。

Thanks in advance. 提前致谢。

Here is a code I have used to reduce the space used and free up Database space and actual Drive space. 这是我用来减少已用空间并释放数据库空间和实际驱动器空间的代码。 Hope this helps. 希望这可以帮助。

USE YourDataBase;
GO
-- Truncate the log by changing the database recovery model to SIMPLE.
ALTER DATABASE YourDataBase
SET RECOVERY SIMPLE;
GO
-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (YourDataBase_log, 1);
GO
-- Reset the database recovery model.
ALTER DATABASE YourDataBase
SET RECOVERY FULL;
GO

Instead of use DBCC SHRINKDATABASE I suggest you to use DBCC SHRINKFILE , obviously your tables should be stored on different FILEGROUP. 我建议您不要使用DBCC SHRINKDATABASE,而应该使用DBCC SHRINKFILE ,显然您的表应该存储在不同的FILEGROUP上。 Then you can reduce the physical size of your database optimizing fragmentation. 然后,您可以减小数据库的物理大小,从而优化碎片。

Hope this could help 希望这可以帮助

You need to shrink your DataBase by using below Query. 您需要使用下面的查询来缩小DataBase

ALTER DATABASE [DBNAME] SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(PTechJew_LOG, 1)
ALTER DATABASE [DBNAME] SET RECOVERY FULL WITH NO_WAIT

After run this query check your log file. 运行此查询后,检查您的日志文件。 Its Worked. 它的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM