In MsSQL, a database can attach with system stored procedure sp_attach_db. The simplest way to execute this stored procedure is with this syntax
EXEC sp_attach_db ‘databaseName’, ‘path/to/database/file’
Or if you want to attach more than 1 file use this syntax
EXEC sp_attach_db ‘databaseName’, ‘path/to/database/file/1’ [,‘path/to/database/file/2’] [,‘path/to/database/file/3’]
You can attach database file up to 16 files. The ‘path/to/database/file’ should no more than 260 characters long.
This stored procedure is a shortcut for creating a database with syntax
CREATE DATABASE databaseName ON (FILENAME = ‘/path/to/database/file/1’ [,FILENAME = ‘/path/to/database/file/2’] [FILENAME = ‘/path/to/database/file/3’] […FILENAME = ‘/path/to/database/file/16’]) FOR ATTACH
FOR ATTACH required all data files, and if multiple log files exists, they must be attach to
Showing posts with label mssql. Show all posts
Showing posts with label mssql. Show all posts
Thursday, April 02, 2009
Wednesday, September 03, 2008
reset nomor identity di MS SQL
cara untuk reset nomor identity di MS SQL menggunakan perintah
contohnya jika kita punya tableA, kita ingin ketika melakukan INSERT, nomor identity menjadi nomor 1
DBCC CHECKIDENT (namatable, RESEED, nomoridentity)
contohnya jika kita punya tableA, kita ingin ketika melakukan INSERT, nomor identity menjadi nomor 1
DBCC CHECKIDENT (tableA, RESEED, 0)
Tuesday, August 05, 2008
NOT IN bisa diganti pake JOIN dan IS NULL
beberapa bulan yg lalu aku mendapatkan sebuah query yg lambat bgt, setelah googling ternyata permasalahannya ada di kondisi NOT IN, di situ dijelaskan kalo NOT IN bisa diganti pake JOIN dan IS NULL, contoh penggunaannya sbb
NOT IN
JOIN dan IS NULL
query ini udah ku coba di MSSQL dan Oracle, hasilnya bisa dieksekusi jauh lebih cepat
NOT IN
SELECT TABLE_A.COLUMN_A
FROM TABLE_A
WHERE TABLE_A.COLUMN_A NOT IN
(
SELECT TABLE_B.COLUMN_A
FROM TABLE_B
)
JOIN dan IS NULL
SELECT TABLE_A.COLUMN_A
FROM TABLE_A
LEFT JOIN TABLE_B
ON TABLE_A.COLUMN_A = TABLE_B.COLUMN_A
WHERE TABLE_B.COLUMN_A IS NULL
query ini udah ku coba di MSSQL dan Oracle, hasilnya bisa dieksekusi jauh lebih cepat
Subscribe to:
Posts (Atom)