select '
DBCC SHRINKFILE(''' + name + ''')
' from sys.database_files where type = 0 and name like 'YOURFILE%'
nice one
select '
DBCC SHRINKFILE(''' + name + ''')
' from sys.database_files where type = 0 and name like 'YOURFILE%'
nice one
just read this to create certificates for you dev box.
just read this to implement your certificates to your box
The following table lists index operations and the type of logging available in each database recovery model for those operations. These recovery models are supported for both online and offline index operations.
| Index operation | Full | Bulk-logged | Simple |
|---|---|---|---|
| ALTER INDEX REORGANIZE | Fully logged | Fully logged | Fully logged |
| ALTER INDEX REBUILD | Fully logged | Minimally logged | Minimally logged |
| CREATE INDEX | Fully logged | Minimally logged | Minimally logged |
| DBCC INDEXDEFRAG | Fully logged | Fully logged | Fully logged |
| DBCC DBREINDEX | Fully logged | Minimally logged | Minimally logged |
| DROP INDEX | Index page deallocation is fully logged; new heap rebuild, if applicable, is fully logged. | Index page deallocation is fully logged; new heap rebuild, if applicable, is minimally logged. | Index page deallocation is fully logged; new heap rebuild, if applicable, is minimally logged. |
For more information, see Choosing the Recovery Model for a Database.
I found this script to create a database snapshot with multiple filegroups/fils, very usefully! many thx to Ravikanth
$computerName = "YOURDBINSTANCE"
$dbName = "YOURDB"
$snapshotName = "YOURSNAPSHOTNAME"
#Load all SQL necesssary assemblies
#this is a common section in all my SQL scripts
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMo") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMoExtended") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMoEnum") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo") | Out-Null
#Get the server and database objects
$server = New-Object Microsoft.SqlServer.Management.Smo.Server($computerName)
$database = $server.Databases[$DBName]
#Define a snapshot database and give the same name as the base databse
$snapshot = New-Object ("Microsoft.SqlServer.Management.Smo.Database") ($computerName,$snapshotName)
$snapshot.DatabaseSnapshotBaseName=$database.Name
#Add all filegroups from the base database to snapshot
foreach ($filegroup in $database.FileGroups) {
$newfg = New-Object ("Microsoft.SqlServer.Management.Smo.FileGroup") ($snapshot,$filegroup.Name)
$snapshot.FileGroups.Add($newfg)
}
#Add all datafiles from each filegroup of the base database to snapshot with a new datafile name
#in this example, I am using .ss as the datafile extension for the snapshot file
#By default, the snapshot files will reside in the same folder as base DB data files
foreach ($filegroup in $database.FileGroups) {
foreach ($datafile in $filegroup.Files) {
$newDataFile = New-Object ("Microsoft.SqlServer.Management.Smo.DataFile") ($snapshot.FileGroups[$filegroup.Name],$datafile.Name,"$($database.PrimaryFilePath)\$($datafile.Name).ss")
$newDataFile.FileName
$snapshot.FileGroups[$filegroup.Name].Files.Add($newDataFile)
}
}
#Create the snapshot
#This is it
$snapshot.Create()
In certain situations you do not want to be a DBA
Last week I was asked by a colleague to take care of a database. No one had bothered to really work/administrate with this database since 2008 but everyone is using this DB….
what I saw there was already a quite a desaster. The database was no longer visible to the SQL Server, just as there was no backup: (
So I tried to query the database again to attach to the SQL server, the message which is then followed lies not make me happy..
File activation failure. The physical file name "xyz \ logDeletion.ldf" may be incorrect. The log can not be rebuilt because the database was not cleanly shut down. Msg 1813, Level 16, State 2, Line 1 Could not open new database 'xyz'. CREATE DATABASE is aborted.
What has happened? The database was not available, a corrupt log file … The weekend may be more beautiful?
After many many hours reading test and I can only recommend always to Satisfy the backup exists.
Everyone who gets into a situation like this, I recommend the following steps.
Test all this steps first with a dummy Database. Paul Randal has a great articel, read this first try this , then try again! understand what you are doing
so far i hope you will never come in this situations….
Export data from Postgres to SQL Server using SSIS
USE yourDataBase; -- SQL disable all triggers - disable all triggers sql server - t sql disable trigger EXEC sp_MSforeachtable @command1="ALTER TABLE ? DISABLE TRIGGER ALL" GO -- SQL disable all constraints - disable all constraints sql server EXEC sp_MSforeachtable @command1="ALTER TABLE ? NOCHECK CONSTRAINT ALL" GO -- How to check if a trigger is disabled USE yourDataBase; SELECT * FROM sys.triggers WHERE name='table'
Sometimes it is necessary that you know how long your DBCC CHECKDB will run and how much percent is already done. Let’s find it out:
sp_who2 'active' SELECT * FROM sys.dm_exec_sessions WHERE session_id = 60 SELECT command,percent_complete FROM sys.dm_exec_requests WHERE session_id = 60
one of the best monitor sql scripts to get detail information for you sql server transactions