Script Andalan Saya

Saya menyebutnya script andalan soalnya sering banget saya pake pas lagi develop atau mengerjakan CR di kantor pake SQL Server 2005. Klo gatau script ini, biasanya kita pake tools SSMS dan biasanya rada lama.

Beberapa script andalan saya:

Shrink log

USE  [DATABASE_NAME]
GO 
ALTER DATABASE [DATABASE_NAME] SET RECOVERY SIMPLE 
GO
USE [DATABASE_NAME]
GO
DBCC SHRINKFILE([DATABASE_FILE_LOG_NAME], 1)
GO
ALTER DATABASE [DATABASE_NAME] SET RECOVERY FULL
GO

Playing with column

IF OBJECT_ID('TEMPDB.DBO.#TEMP') IS NOT NULL
   DROP TABLE #TEMP
 
CREATE TABLE #TEMP
(
    COL1 VARCHAR(10)
)
 
-- MENAMBAH KOLOM
ALTER TABLE #TEMP ADD COL_NEW VARCHAR(10)
 
-- MERUBAH TIPE KOLOM
ALTER TABLE #TEMP ALTER COLUMN COL_NEW INT
 
-- DROP COLUMN
ALTER TABLE #TEMP DROP COLUMN COL1
 
-- MENAMBAH NILAI DEFAULT PADA KOLOM
ALTER TABLE #TEMP ADD DEFAULT 0 FOR COL_NEW
 
SELECT *
FROM #TEMP

CMIIW 🙂

Marifnst, 2015-09-05

Leave a Reply

Your email address will not be published. Required fields are marked *

Afiseaza emoticoanele Locco.Ro