Wednesday, November 15, 2017

Slow Database First Code Generation Visual Studio

Running the following on the DB worked for me:
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION=ON
Then, after the update, setting it back using:
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION=OFF

Wednesday, October 18, 2017

Renaming Primary key and references in all tables sql server

Use sp_fkeys procedure to get all foreign keys

EXEC sp_fkeys 'Students', 'Academics'

Use nimble text to update keys

UPDATE $5.$6
SET $7 = $1.$2.$3
FROM $5.$6
INNER JOIN $1.$2 on $5.$6.$7 =  $1.$2.$3

Saturday, June 3, 2017

SQL SERVER – Unable to Attach Database – File Activation Failure – The Log Cannot be Rebuilt

Method 1: 

Src: https://www.mssqltips.com/sqlservertip/3579/how-to-attach-a-sql-server-database-without-a-transaction-log-and-with-open-transactions/

Last Resort:

CREATE DATABASE SQLAuthority
ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\DATA\file.mdf')
FOR ATTACH_FORCE_REBUILD_LOG
Src:
https://blog.sqlauthority.com/2016/11/04/sql-server-unable-attach-database-file-activation-failure-log-cannot-rebuilt/

Thursday, May 18, 2017

7-Zip command line to zip all the content of a folder

7z a archivename pathtofolder *

SQl SERVER: How to set recovery model to SIMPLE for all databases

Steps on how to set recovery model to SIMPLE for all databases 

Step 1. Run script
SELECT 'ALTER DATABASE ' + [Name] + ' SET RECOVERY SIMPLE'
FROM sys.databases
WHERE recovery_model_desc = 'FULL'
Step 2. Copy output and execute

SQl SERVER: How to set recovery model to FULL for all databases

Steps on how to set recovery model to FULL for all databases 

Step 1. Run script
SELECT 'ALTER DATABASE ' + [Name] + ' SET RECOVERY FULL'
FROM sys.databases
WHERE recovery_model_desc = 'SIMPLE'
Step 2. Copy output and execute

Monday, April 10, 2017

How to Shrink MS SQL Server Transaction Logs

Using T-SQL

ALTER DATABASE [db name]
SET RECOVERY SIMPLE
GO
DBCC SHRINKFILE('log_file_name.ldf', 100)--whatever size you need in MB's 
GO
ALTER DATABASE [db name]
SET RECOVERY FULL

To Find Log file name use below T-SQL

use [db name]
GO
select name as [log_file_name] from sys.database_files
where [type_desc] = 'LOG'

Saturday, April 8, 2017

Windows Installer MSI Error 1001/2869

Make sure to disable any antivirus software

Solution 1:
  1. Run cmd as administrator
  2. go to directory containing the msi file using "cd"
  3. then run "msiexec /i File.msi
Solution 2:
  1. Run cmd as administrator
  2. go to directory containing the msi file using "cd"
  3. then run msiexec /a File.msi /qb targetdir="e:/NewPath/"
  4. this will extract the contents of file where you may be able to launch the application