IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ObjectList]') AND type in (N'U'))
BEGIN
-- 조건 속성 삭제
ALTER TABLE [dbo].[ObjectList] DROP CONSTRAINT [DF_ObjectList_IsDel];
ALTER TABLE [dbo].[ObjectList] DROP CONSTRAINT [DF_ObjectList_IsUse];
ALTER TABLE [dbo].[ObjectList] DROP CONSTRAINT [DF_ObjectList_CreateDate];
ALTER TABLE [dbo].[ObjectList] DROP CONSTRAINT [PK_ObjectList];
-- 기존 원본 테이블 이름 변경
exec sp_rename 'ObjectList', 'ObjectList_Backup_210617'
-- 복사할 신규 테이블 생성
CREATE TABLE [dbo].[ObjectList](
[ObjectUID] [int] IDENTITY(1,1) NOT NULL,
[ObjectID] [int] NOT NULL,
[CreateDate] [datetime] NULL CONSTRAINT [DF_ObjectList_CreateDate] DEFAULT (GETDATE()),
[CreateKey] [int] NULL,
[CreateIp] [char](15) NULL,
[IsUse] [tinyint] NOT NULL CONSTRAINT [DF_ObjectList_IsUse] DEFAULT(0),
[IsDel] [bit] NOT NULL CONSTRAINT [DF_ObjectList_IsDel] DEFAULT(0),
CONSTRAINT [PK_ObjectList] PRIMARY KEY CLUSTERED
(
[ObjectUID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
-- 테이블 복사.
SET IDENTITY_INSERT [dbo].[ObjectList] ON
INSERT INTO [dbo].[ObjectList](ObjectUID,ObjectID,CreateDate,CreateKey,CreateIp,IsUse,IsDel)
SELECT ObjectUID,ObjectID,CreateDate,CreateKey,CreateIp,IsUse,IsDel FROM [dbo].[ObjectList_Backup_210617];
SET IDENTITY_INSERT [dbo].[ObjectList] OFF
-- 구 테이블 삭제
DROP TABLE [dbo].[ObjectList_Backup_210617]
END
GO
'[ Programing ] > Database' 카테고리의 다른 글
MS-SQL Job 스케쥴러 확인 (0) | 2021.08.26 |
---|---|
MS-SQL 임시 테이블 (0) | 2021.07.26 |
[MS-SQL] Job Drop & Create (0) | 2021.07.15 |
MS-SQL 인덱스 재구성. (0) | 2021.05.27 |
MS-SQL UPDATE STATISTICS 통계 업데이트 (0) | 2021.05.27 |