반응형
/********************************************************************************************
-- Title : [2k5] 컬럼 추가시 ALTER TABLE ~ ADD COLUMN과 CREATE TABLE ~ INSERT 비교
-- Reference : feelanet.com
-- Key word : 컬럼 추가 add column
********************************************************************************************/
-- not null이면서 default를 가지는 컬럼을 추가시 alter table ~ add column 보다 create table 후
-- insert 하는 경우가 빠른 경우도 있드라...

use credit;
go
/*
-- ALTER TABE ~ ADD COLUMN을 이용한 컬럼 추가
*/
select * into charge_addcol from charge;
go

set statistics time on;
go

alter table charge_addcol
 add tel3 char(30) not null default '';
go
/*
SQL Server 구문 분석 및 컴파일 시간:
   CPU 시간 = 0ms, 경과 시간 = 2ms.
SQL Server 구문 분석 및 컴파일 시간:
   CPU 시간 = 0ms, 경과 시간 = 16ms.
SQL Server 실행 시간:
   CPU 시간 = 2032ms, 경과 시간 = 7907ms.
SQL Server 실행 시간:
   CPU 시간 = 2032ms, 경과 시간 = 7928ms.
*/


/*
-- CREATE TABE ~ 이후 INSERT
*/
CREATE TABLE [charge_insertcol] (
 [charge_no] [numeric_id] IDENTITY (1, 1) NOT NULL ,
 [member_no] [numeric_id] NOT NULL ,
 [provider_no] [numeric_id] NOT NULL ,
 [category_no] [numeric_id] NOT NULL ,
 [charge_dt] [datetime] NOT NULL ,
 [charge_amt] [money] NOT NULL ,
 [statement_no] [numeric_id] NOT NULL,
 [charge_code] [status_code] NOT NULL
 ,tel3 char(30) not null
);
go

--시간 측정
insert charge_insertcol
select member_no, provider_no, category_no, charge_dt, charge_amt
     , statement_no, charge_code
     , ''
from charge;
go
/*
SQL Server 구문 분석 및 컴파일 시간:
   CPU 시간 = 0ms, 경과 시간 = 10ms.
SQL Server 실행 시간:
   CPU 시간 = 406ms, 경과 시간 = 2312ms.
*/

반응형

+ Recent posts