Skip to content

Instantly share code, notes, and snippets.

@petesql
Created January 28, 2019 19:47
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 petesql/c84bf6a530b5eaca51e05f1765926feb to your computer and use it in GitHub Desktop.
Save petesql/c84bf6a530b5eaca51e05f1765926feb to your computer and use it in GitHub Desktop.
attach_database_without_log
CREATE DATABASE [funky_db]
ON ( NAME = funkydb_data, FILENAME = 'c:\sql\funkdata.mdf' )
LOG ON ( NAME = funkydb_log, FILENAME = 'c:\sql\funklog.ldf')
USE [funky_db]
GO
CREATE TABLE [funky_people] (firstName VARCHAR(64), surname VARCHAR(64), dateofbirth DATE, funkLevel INT)
INSERT INTO [funky_people] VALUES ('funk','master','1969-01-01',100)
SELECT *
FROM [funky_people]
--------------------------------------------------------------------------------------------------------------
USE [master]
GO
CREATE DATABASE [funky_db] ON
( FILENAME = N'C:\sql\funkdata.mdf' )
FOR ATTACH
GO
USE [master]
GO
EXEC sp_attach_single_file_db
@dbname='funky_db',
@physname=N'c:\sql\funkdata.mdf'
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment