Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance This article describes how to shrink a data or log file in SQL Server by using SQL Server Management Studio or Transact-SQL. Shrinking data f
42 SET @dbFilesCursor = CURSOR for select sys.master_files.name from sys.master_files, [master].[sys].[databases] where databases.name = @dbname and databases.database_id = sys.master_files.database_id 43 open @dbFilesCursor 44 FETCH NEXT FROM @dbFilesCursor INTO @dbFile 45 WHILE @@...
This article describes how to shrink a database in SQL Server by using Object Explorer in 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...
@dbname,']'))41EXECsp_executesql@tempTSQL42SET@dbFilesCursor=CURSORforselectsys.master_files.namefromsys.master_files,[master].[sys].[databases]wheredatabases.name=@dbnameanddatabases.database_id=sys.master_files.database_id43open@dbFilesCursor44FETCHNEXTFROM@dbFilesCursorINTO@dbFile45WHILE@@FET...
SQL Server 的語法: syntaxsql 複製 DBCC SHRINKDATABASE ( database_name | database_id | 0 [ , target_percent ] [ , { NOTRUNCATE | TRUNCATEONLY } ] ) [ WITH { [ WAIT_AT_LOW_PRIORITY [ ( <wait_at_low_priority_option_list> )] ] [ , NO_INFOMSGS] } ] < ...
Now, after creating this database, the file size has become more than 4GB and it reduced the drive space which was earlier 250GB to 245GB. Approx 5GB is now increased in total. SHRINK FILE Now, simply use the manual T-SQL command as follows to shrink MDF file: ...
The -c and -f parameters cause SQL Server to start in a minimum configuration mode that has a tempdb size of 1 MB for the data file, and 0.5 MB for the log file. The -mSQLCMD parameter prevents any other application than sqlcmd from taking over the single-user connect...
database_name|database_id| 0 The database name or ID to be shrunk. 0 specifies that the current database is used. target_percent The percentage of free space that you want left in the database file after the shrink operation completes. ...
The database being shrunk does not have to be in single-user mode; other users can be working in the database when the file is shrunk. You do not have to run the instance of SQL Server in single-user mode to shrink the system databases. ...
“Minimum size” - Shrinks the file to the smallest possible size. “Specific size in MB” - Shrinks the file to a specific size in megabytes. Click the “OK” button to initiate the shrink operation. Shrinking a Database using T-SQL ...