본문 바로가기
MS-SQL/Query

데이터베이스 연결 간단한 예제

by Hwoarang757 2013. 2. 5.

sp_attach_db 를 이용하지 않고 직접 연결 창을 이용해 스크립트를 생성해 보았다.

 

USE [master]

GO

CREATE DATABASE [TEST_BACKUP] ON

( FILENAME = N'M:\TEST_Backup\TEST_Backup.mdf' ),

( FILENAME = N'M:\TEST_Backup\TEST_Backup_Log.ldf' ),

( FILENAME = N'M:\TEST_Backup\FG_2007.ndf' ),

( FILENAME = N'M:\TEST_Backup\FG_2008.ndf' ),

( FILENAME = N'M:\TEST_Backup\FG_2009.ndf' ),

( FILENAME = N'M:\TEST_Backup\FG_2010.ndf' ),

( FILENAME = N'M:\TEST_Backup\FG_2011.ndf' ),

( FILENAME = N'M:\TEST_Backup\FG_2012.ndf' ),

( FILENAME = N'M:\TEST_Backup\FG_2013.ndf' ),

( FILENAME = N'M:\TEST_Backup\FG_9999.ndf' )

 FOR ATTACH

GO

if exists (select name from master.sys.databases sd where name = N'TEST_BACKUP' and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [TEST_BACKUP].dbo.sp_changedbowner @loginame=N'SECSERVER\ServerSADB', @map=false

GO