Our social:

Thursday, 5 February 2015

Backup Database

Script di bawah ini tujuannya untuk MemBackup Database mode FULL Backup


DECLARE @name VARCHAR(50)
DECLARE @database VARCHAR(50)
DECLARE @path VARCHAR(256)
DECLARE @fileName VARCHAR(256)
DECLARE @fileDate VARCHAR(20)

SET @path = 'D:\' --- TUjuan Simpan File
SET @database = 'otomax'

SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) + '_' + REPLACE(CONVERT(VARCHAR(20),GETDATE(),108),':','')

DECLARE db_cursor CURSOR FOR

SELECT name
FROM master.dbo.sysdatabases
WHERE name IN (@database)

OPEN db_cursor

FETCH NEXT FROM db_cursor INTO @name
WHILE @@FETCH_STATUS = 0

BEGIN

SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName
FETCH NEXT FROM db_cursor INTO @name

END

CLOSE db_cursor

DEALLOCATE db_cursor

untuk bisa melakukan Hal ini, anda harus tahu bagaimana cara eksekusi sql via SQL Management Studio
langkah – langkahnya
1. Masuk Sql Management Studio
2. Buat New Query dan masukkan syntax tersbut di halaman Query
3. Klik Execute
4. finish, dan lihat reportnya
Note : lamanya proses tergantung besar kecilnya database
semoga bermanfaat

0 comments:

Post a Comment