SlideShare a Scribd company logo
Shrink a Database
SQL Server 2016
Other Versions
Applies To: SQL Server 2016
This topic describes how to shrink a database by using Object in SQL Server 2016 by using SQL Server
Management Studio or Transact-SQL.
Shrinking data files recovers space by moving pages of data from the end of the file to unoccupied space
closer to the front of the file. When enough free space is created at the end of the file, data pages at end
of the file can be deallocated and returned to the file system.
In This Topic
 Before you begin:
Limitations and Restrictions
Recommendations
Security
 To shrink a database, using:
SQL Server Management Studio
Transact-SQL
 Follow Up: You shrink a database
Before You Begin
Limitations and Restrictions
 The database cannot be made smaller than the minimum size of the database. The minimum size
is the size specified when the database was originally created, or the last explicit size set by using
a file-size-changing operation, such as DBCC SHRINKFILE. For example, if a database was
originally created with a size of 10 MB and grew to 100 MB, the smallest size the database could
be reduced to is 10 MB, even if all the data in the database has been deleted.
 You cannot shrink a database while the database is being backed up. Conversely, you cannot
backup a database while a shrink operation on the database is in process.
 DBCC SHRINKDATABASE will fail when it encounters an xVelocity memory optimized columnstore
index. Work completed before encountering the columnstore index will succeed so the database
might be smaller. To complete DBCC SHRINKDATABASE, disable all columnstore indexes before
executing DBCC SHRINKDATABASE, and then rebuild the columnstore indexes.
Recommendations
 To view the current amount of free (unallocated) space in the database. For more information,
see Display Data and Log Space Information for a Database
 Consider the following information when you plan to shrink a database:
o A shrink operation is most effective after an operation that creates lots of unused space,
such as a truncate table or a drop table operation.
o Most databases require some free space to be available for regular day-to-day
operations. If you shrink a database repeatedly and notice that the database size grows
again, this indicates that the space that was shrunk is required for regular operations. In
these cases, repeatedly shrinking the database is a wasted operation.
o A shrink operation does not preserve the fragmentation state of indexes in the database,
and generally increases fragmentation to a degree. This is another reason not to
repeatedly shrink the database.
o Unless you have a specific requirement, do not set the AUTO_SHRINK database option to
ON.
Security
Permissions
Requires membership in the sysadmin fixed server role or the db_owner fixed database role.
Using SQL Server Management Studio
To shrink a database
1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand
that instance.
2. Expand Databases, and then right-click the database that you want to shrink.
3. Point to Tasks, point to Shrink, and then click Database.
Database
Displays the name of the selected database.
Current allocated space
Displays the total used and unused space for the selected database.
Available free space
Displays the sum of free space in the log and data files of the selected database.
Reorganize files before releasing unused space
Selecting this option is equivalent to executing DBCC SHRINKDATABASE specifying a target
percent option. Clearing this option is equivalent to executing DBCC SHRINKDATABASE with
TRUNCATEONLY option. By default, this option is not selected when the dialog is opened. If this
option is selected, the user must specify a target percent option.
Maximum free space in files after shrinking
Enter the maximum percentage of free space to be left in the database files after the database has
been shrunk. Permissible values are between 0 and 99.
4. Click OK.
Using Transact-SQL
To shrink a database
1. Connect to the Database Engine.
2. From the Standard bar, click New Query.
3. Copy and paste the following example into the query window and click Execute. This example
uses DBCC SHRINKDATABASE to decreases the size of the data and log files in
the UserDB database and to allow for 10 percent free space in the database.
Transact-SQL
DBCC SHRINKDATABASE (UserDB, 10);
GO
Follow Up: After you shrink a database
Data that is moved to shrink a file can be scattered to any available location in the file. This causes index
fragmentation and can slow the performance of queries that search a range of the index. To eliminate the
fragmentation, consider rebuilding the indexes on the file after shrinking.
See Also
Shrink a File
sys.databases (Transact-SQL)
sys.database_files (Transact-SQL)
DBCC (Transact-SQL)
DBCC SHRINKFILE (Transact-SQL)
Database Files and Filegroups
Ad

More Related Content

What's hot (20)

Hbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBaseHbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBase
phanleson
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
Tharun Srinivasa
 
Physical architecture of sql server
Physical architecture of sql serverPhysical architecture of sql server
Physical architecture of sql server
Divya Sharma
 
Discover database
Discover databaseDiscover database
Discover database
Wayne Weixin
 
Discover Database
Discover DatabaseDiscover Database
Discover Database
Wayne Weixin
 
Setting up your DUSP ArcGIS Environment
Setting up your DUSP ArcGIS EnvironmentSetting up your DUSP ArcGIS Environment
Setting up your DUSP ArcGIS Environment
DUSPviz
 
Backup and restore
Backup and restoreBackup and restore
Backup and restore
Riteshkiit
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table design
phanleson
 
Summary of "Google's Big Table" at nosql summer reading in Tokyo
Summary of "Google's Big Table" at nosql summer reading in TokyoSummary of "Google's Big Table" at nosql summer reading in Tokyo
Summary of "Google's Big Table" at nosql summer reading in Tokyo
CLOUDIAN KK
 
Cloudyn - Multi vendor Cloud management
Cloudyn - Multi vendor Cloud management Cloudyn - Multi vendor Cloud management
Cloudyn - Multi vendor Cloud management
Sandeep Sharma IIMK Smart City,IoT,Bigdata,Cloud,BI,DW
 
Column oriented database
Column oriented databaseColumn oriented database
Column oriented database
Kanike Krishna
 
Data replication
Data replicationData replication
Data replication
ssuser1eca7d
 
Bigtable
BigtableBigtable
Bigtable
nextlib
 
Oracle interview question & answers
Oracle interview question & answersOracle interview question & answers
Oracle interview question & answers
Mohammad Wasi
 
Write behind logging
Write behind loggingWrite behind logging
Write behind logging
Pouyan Rezazadeh
 
Dial Tone Portability
Dial Tone PortabilityDial Tone Portability
Dial Tone Portability
niteshitimpulse
 
data deduplication
data deduplicationdata deduplication
data deduplication
ssuser1eca7d
 
Google Bigtable paper presentation
Google Bigtable paper presentationGoogle Bigtable paper presentation
Google Bigtable paper presentation
vanjakom
 
Hadoop architecture-tutorial
Hadoop  architecture-tutorialHadoop  architecture-tutorial
Hadoop architecture-tutorial
vinayiqbusiness
 
Big table presentation-final
Big table presentation-finalBig table presentation-final
Big table presentation-final
Yunming Zhang
 
Hbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBaseHbase in action - Chapter 09: Deploying HBase
Hbase in action - Chapter 09: Deploying HBase
phanleson
 
MongoDB Replication and Sharding
MongoDB Replication and ShardingMongoDB Replication and Sharding
MongoDB Replication and Sharding
Tharun Srinivasa
 
Physical architecture of sql server
Physical architecture of sql serverPhysical architecture of sql server
Physical architecture of sql server
Divya Sharma
 
Setting up your DUSP ArcGIS Environment
Setting up your DUSP ArcGIS EnvironmentSetting up your DUSP ArcGIS Environment
Setting up your DUSP ArcGIS Environment
DUSPviz
 
Backup and restore
Backup and restoreBackup and restore
Backup and restore
Riteshkiit
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table design
phanleson
 
Summary of "Google's Big Table" at nosql summer reading in Tokyo
Summary of "Google's Big Table" at nosql summer reading in TokyoSummary of "Google's Big Table" at nosql summer reading in Tokyo
Summary of "Google's Big Table" at nosql summer reading in Tokyo
CLOUDIAN KK
 
Column oriented database
Column oriented databaseColumn oriented database
Column oriented database
Kanike Krishna
 
Bigtable
BigtableBigtable
Bigtable
nextlib
 
Oracle interview question & answers
Oracle interview question & answersOracle interview question & answers
Oracle interview question & answers
Mohammad Wasi
 
data deduplication
data deduplicationdata deduplication
data deduplication
ssuser1eca7d
 
Google Bigtable paper presentation
Google Bigtable paper presentationGoogle Bigtable paper presentation
Google Bigtable paper presentation
vanjakom
 
Hadoop architecture-tutorial
Hadoop  architecture-tutorialHadoop  architecture-tutorial
Hadoop architecture-tutorial
vinayiqbusiness
 
Big table presentation-final
Big table presentation-finalBig table presentation-final
Big table presentation-final
Yunming Zhang
 

Similar to Sql data shrink steps (20)

Db2 performance tuning for dummies
Db2 performance tuning for dummiesDb2 performance tuning for dummies
Db2 performance tuning for dummies
Angel Dueñas Neyra
 
DBA 101 : Calling all New Database Administrators (WP)
DBA 101 : Calling all New Database Administrators (WP)DBA 101 : Calling all New Database Administrators (WP)
DBA 101 : Calling all New Database Administrators (WP)
Gustavo Rene Antunez
 
tablespaces and datafiles in database administration
tablespaces and datafiles in database administrationtablespaces and datafiles in database administration
tablespaces and datafiles in database administration
AsharJaved14
 
ORACLE ARCHITECTURE
ORACLE ARCHITECTUREORACLE ARCHITECTURE
ORACLE ARCHITECTURE
Manohar Tatwawadi
 
PostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingPostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / Sharding
Amir Reza Hashemi
 
Dbcc.doc
Dbcc.docDbcc.doc
Dbcc.doc
kumarranjith2
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-features
Navneet Upneja
 
Oracle RAC 12c and Policy-Managed Databases, a Technical Overview
Oracle RAC 12c and Policy-Managed Databases, a Technical OverviewOracle RAC 12c and Policy-Managed Databases, a Technical Overview
Oracle RAC 12c and Policy-Managed Databases, a Technical Overview
Ludovico Caldara
 
FAQ on Dedupe NetApp
FAQ on Dedupe NetAppFAQ on Dedupe NetApp
FAQ on Dedupe NetApp
Ashwin Pawar
 
Presentation day2 oracle12c
Presentation day2 oracle12cPresentation day2 oracle12c
Presentation day2 oracle12c
Pradeep Srivastava
 
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
nesmaddy
 
RMAN in 12c: The Next Generation (WP)
RMAN in 12c: The Next Generation (WP)RMAN in 12c: The Next Generation (WP)
RMAN in 12c: The Next Generation (WP)
Gustavo Rene Antunez
 
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Knut Relbe-Moe [MVP, MCT]
 
Shared_Pool_Monitoring THREE APPROACHES TO Shared Pool Monitoring
Shared_Pool_Monitoring THREE APPROACHES TO Shared Pool MonitoringShared_Pool_Monitoring THREE APPROACHES TO Shared Pool Monitoring
Shared_Pool_Monitoring THREE APPROACHES TO Shared Pool Monitoring
ssuserfe43fd
 
Dba tuning
Dba tuningDba tuning
Dba tuning
Maximiliano Accotto
 
Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013
Ivan Sanders
 
Optimization in essbase
Optimization in essbaseOptimization in essbase
Optimization in essbase
Ajay singh chouhan
 
Using oracle12c pluggable databases to archive
Using oracle12c pluggable databases to archiveUsing oracle12c pluggable databases to archive
Using oracle12c pluggable databases to archive
Secure-24
 
Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)
Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)
Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)
yoonus ch
 
Presentation day1oracle 12c
Presentation day1oracle 12cPresentation day1oracle 12c
Presentation day1oracle 12c
Pradeep Srivastava
 
Db2 performance tuning for dummies
Db2 performance tuning for dummiesDb2 performance tuning for dummies
Db2 performance tuning for dummies
Angel Dueñas Neyra
 
DBA 101 : Calling all New Database Administrators (WP)
DBA 101 : Calling all New Database Administrators (WP)DBA 101 : Calling all New Database Administrators (WP)
DBA 101 : Calling all New Database Administrators (WP)
Gustavo Rene Antunez
 
tablespaces and datafiles in database administration
tablespaces and datafiles in database administrationtablespaces and datafiles in database administration
tablespaces and datafiles in database administration
AsharJaved14
 
PostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / ShardingPostgreSQL Table Partitioning / Sharding
PostgreSQL Table Partitioning / Sharding
Amir Reza Hashemi
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-features
Navneet Upneja
 
Oracle RAC 12c and Policy-Managed Databases, a Technical Overview
Oracle RAC 12c and Policy-Managed Databases, a Technical OverviewOracle RAC 12c and Policy-Managed Databases, a Technical Overview
Oracle RAC 12c and Policy-Managed Databases, a Technical Overview
Ludovico Caldara
 
FAQ on Dedupe NetApp
FAQ on Dedupe NetAppFAQ on Dedupe NetApp
FAQ on Dedupe NetApp
Ashwin Pawar
 
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
nesmaddy
 
RMAN in 12c: The Next Generation (WP)
RMAN in 12c: The Next Generation (WP)RMAN in 12c: The Next Generation (WP)
RMAN in 12c: The Next Generation (WP)
Gustavo Rene Antunez
 
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Unity Connect - Getting SQL Spinning with SharePoint - Best Practices for the...
Knut Relbe-Moe [MVP, MCT]
 
Shared_Pool_Monitoring THREE APPROACHES TO Shared Pool Monitoring
Shared_Pool_Monitoring THREE APPROACHES TO Shared Pool MonitoringShared_Pool_Monitoring THREE APPROACHES TO Shared Pool Monitoring
Shared_Pool_Monitoring THREE APPROACHES TO Shared Pool Monitoring
ssuserfe43fd
 
Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013Real world business workflow with SharePoint designer 2013
Real world business workflow with SharePoint designer 2013
Ivan Sanders
 
Using oracle12c pluggable databases to archive
Using oracle12c pluggable databases to archiveUsing oracle12c pluggable databases to archive
Using oracle12c pluggable databases to archive
Secure-24
 
Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)
Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)
Oracle 10g to 11g upgrade on sap(10.2.0.5.0 to 11.2.0.3)
yoonus ch
 
Ad

Recently uploaded (20)

Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Avnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights FlyerAvnet Silica's PCIM 2025 Highlights Flyer
Avnet Silica's PCIM 2025 Highlights Flyer
WillDavies22
 
Value Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous SecurityValue Stream Mapping Worskshops for Intelligent Continuous Security
Value Stream Mapping Worskshops for Intelligent Continuous Security
Marc Hornbeek
 
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E..."Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
"Boiler Feed Pump (BFP): Working, Applications, Advantages, and Limitations E...
Infopitaara
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
railway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forgingrailway wheels, descaling after reheating and before forging
railway wheels, descaling after reheating and before forging
Javad Kadkhodapour
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Ad

Sql data shrink steps

  • 1. Shrink a Database SQL Server 2016 Other Versions Applies To: SQL Server 2016 This topic describes how to shrink a database by using Object in SQL Server 2016 by using SQL Server Management Studio or Transact-SQL. Shrinking data files recovers space by moving pages of data from the end of the file to unoccupied space closer to the front of the file. When enough free space is created at the end of the file, data pages at end of the file can be deallocated and returned to the file system. In This Topic  Before you begin: Limitations and Restrictions Recommendations Security  To shrink a database, using: SQL Server Management Studio Transact-SQL  Follow Up: You shrink a database Before You Begin Limitations and Restrictions  The database cannot be made smaller than the minimum size of the database. The minimum size is the size specified when the database was originally created, or the last explicit size set by using a file-size-changing operation, such as DBCC SHRINKFILE. For example, if a database was originally created with a size of 10 MB and grew to 100 MB, the smallest size the database could be reduced to is 10 MB, even if all the data in the database has been deleted.  You cannot shrink a database while the database is being backed up. Conversely, you cannot backup a database while a shrink operation on the database is in process.  DBCC SHRINKDATABASE will fail when it encounters an xVelocity memory optimized columnstore index. Work completed before encountering the columnstore index will succeed so the database might be smaller. To complete DBCC SHRINKDATABASE, disable all columnstore indexes before executing DBCC SHRINKDATABASE, and then rebuild the columnstore indexes. Recommendations  To view the current amount of free (unallocated) space in the database. For more information, see Display Data and Log Space Information for a Database  Consider the following information when you plan to shrink a database: o A shrink operation is most effective after an operation that creates lots of unused space, such as a truncate table or a drop table operation. o Most databases require some free space to be available for regular day-to-day operations. If you shrink a database repeatedly and notice that the database size grows again, this indicates that the space that was shrunk is required for regular operations. In these cases, repeatedly shrinking the database is a wasted operation.
  • 2. o A shrink operation does not preserve the fragmentation state of indexes in the database, and generally increases fragmentation to a degree. This is another reason not to repeatedly shrink the database. o Unless you have a specific requirement, do not set the AUTO_SHRINK database option to ON. Security Permissions Requires membership in the sysadmin fixed server role or the db_owner fixed database role. Using SQL Server Management Studio To shrink a database 1. In Object Explorer, connect to an instance of the SQL Server Database Engine, and then expand that instance. 2. Expand Databases, and then right-click the database that you want to shrink. 3. Point to Tasks, point to Shrink, and then click Database. Database Displays the name of the selected database. Current allocated space Displays the total used and unused space for the selected database. Available free space Displays the sum of free space in the log and data files of the selected database. Reorganize files before releasing unused space Selecting this option is equivalent to executing DBCC SHRINKDATABASE specifying a target percent option. Clearing this option is equivalent to executing DBCC SHRINKDATABASE with TRUNCATEONLY option. By default, this option is not selected when the dialog is opened. If this option is selected, the user must specify a target percent option. Maximum free space in files after shrinking Enter the maximum percentage of free space to be left in the database files after the database has been shrunk. Permissible values are between 0 and 99. 4. Click OK. Using Transact-SQL To shrink a database 1. Connect to the Database Engine. 2. From the Standard bar, click New Query. 3. Copy and paste the following example into the query window and click Execute. This example uses DBCC SHRINKDATABASE to decreases the size of the data and log files in the UserDB database and to allow for 10 percent free space in the database. Transact-SQL DBCC SHRINKDATABASE (UserDB, 10); GO Follow Up: After you shrink a database Data that is moved to shrink a file can be scattered to any available location in the file. This causes index fragmentation and can slow the performance of queries that search a range of the index. To eliminate the fragmentation, consider rebuilding the indexes on the file after shrinking. See Also
  • 3. Shrink a File sys.databases (Transact-SQL) sys.database_files (Transact-SQL) DBCC (Transact-SQL) DBCC SHRINKFILE (Transact-SQL) Database Files and Filegroups