Skip to content

Instantly share code, notes, and snippets.

@zippy1981
Created September 8, 2011 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zippy1981/1204807 to your computer and use it in GitHub Desktop.
Save zippy1981/1204807 to your computer and use it in GitHub Desktop.
Demonstrating CREATE DATABASE file case insensitivity to @grrl_geek
USE master;
GO
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'dropMe')
DROP DATABASE [dropMe]
GO
CREATE DATABASE dropMe;
GO
DECLARE @fileName VARCHAR(MAX)
SELECT @fileName = LOWER(physical_name) from dropMe.sys.database_files WHERE type_desc='ROWS'
SELECT @fileName as [@fileName]
EXEC sp_detach_db 'dropMe'
DECLARE @strSql NVARCHAR(MAX)
SELECT @strSql = 'CREATE DATABASE dropme ON (FILENAME=''' + @fileName + ''') FOR ATTACH'
EXEC sp_executesql @strSql
GO
SELECT physical_name from dropMe.sys.database_files WHERE type_desc='ROWS'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment