블로그 이미지
bedbmsguru

Notice

Recent Comment

Recent Trackback

Archive

calendar

        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30  
  • 26,871total
  • 9today
  • 6yesterday
2010.11.03 11:33 SQL SERVER

declare foreignkey_make_cursor cursor for
    select name, parent_object_id, referenced_object_id, delete_referential_action, update_referential_action from sys.foreign_keys

declare @foreignkey_name as varchar(100)
declare @current_table_id as int
declare @refrenced_table_id as int
declare @delete_refrencial_action as tinyint
declare @update_refrencial_action as tinyint

open foreignkey_make_cursor
fetch next from foreignkey_make_cursor    into @foreignkey_name, @current_table_id, @refrenced_table_id, @delete_refrencial_action, @update_refrencial_action
while (@@fetch_status = 0)
begin
    declare @result_query  as varchar(3000)
    set @result_query ='alter table ' + object_name(@current_table_id)
    set @result_query = @result_query  + ' add constraint ' + @foreignkey_name + ' foreign key '
    set @result_query = @result_query  + '('
   
    --foreign key 에  들어갈 column 을 불러오는 커서
    declare process_column_cursor cursor for
        select b.name from sys.foreign_key_columns as a
        inner join sys.columns as b
        on a.parent_object_id = b.object_id
        and a.parent_column_id = b.column_id
        where parent_object_id = @current_table_id

        declare @fkcolumn sysname
        declare @fkfirstcolumn bit set @fkfirstcolumn = 1

        open process_column_cursor
        fetch next from process_column_cursor into @fkcolumn
        while (@@fetch_status = 0)
        begin
            if (@fkfirstcolumn = 1)
                set @fkfirstcolumn = 0
            else
                set @result_query = @result_query + ', '

            set @result_query = @result_query + @fkcolumn

            fetch next from process_column_cursor into @fkcolumn
        end
        close process_column_cursor
        deallocate process_column_cursor
    --###########process_column_cursor 커서의 끝###############################
          
    set @result_query = @result_query  + ') '
    set @result_query = @result_query  + 'references ' + object_name(@refrenced_table_id) +'('
   
    --원본테이블에서 참조되고 있는 column 을 불러오는 커서   
    declare process_rdcolumn_cursor cursor for
        select b.name from sys.foreign_key_columns as a
        inner join sys.columns as b
        on a.referenced_object_id= b.object_id
        and a.referenced_column_id = b.column_id
        where referenced_object_id = @refrenced_table_id

        declare @rdcolumn sysname
        declare @rdfirstcolumn bit set @rdfirstcolumn = 1

        open process_rdcolumn_cursor
        fetch next from process_rdcolumn_cursor into @rdcolumn
        while (@@fetch_status = 0)
        begin
            if (@rdfirstcolumn = 1)
                set @rdfirstcolumn = 0
            else
                set @result_query = @result_query + ', '

            set @result_query = @result_query + @rdcolumn
            fetch next from process_rdcolumn_cursor into @rdcolumn
        end
    close process_rdcolumn_cursor
    deallocate process_rdcolumn_cursor
    --###########process_rdcolumn_cursor 커서의 끝###############################

    set @result_query = @result_query  + ')'
   
    if(@delete_refrencial_action = 0)
        set @result_query = @result_query + ' on delete no action'
    else if(@delete_refrencial_action = 1)
        set @result_query = @result_query + ' on delete cascade'
    else if(@delete_refrencial_action = 2)
        set @result_query = @result_query + ' on delete set null'
    else if(@delete_refrencial_action = 3)
        set @result_query = @result_query + ' on delete set default'
   
       
       
       
    if(@update_refrencial_action = 0)
        set @result_query = @result_query + ' on update no action'
    else if(@update_refrencial_action = 1)
        set @result_query = @result_query + ' on update cascade'
    else if(@update_refrencial_action = 2)
        set @result_query = @result_query + ' on update set null'
    else if(@update_refrencial_action = 3)
        set @result_query = @result_query + ' on update set default'
   
    print @result_query
    fetch next from foreignkey_make_cursor    into @foreignkey_name, @current_table_id, @refrenced_table_id, @delete_refrencial_action, @update_refrencial_action
end
close foreignkey_make_cursor
deallocate foreignkey_make_cursor
저작자 표시
신고
posted by bedbmsguru
2010.11.03 11:27 SQL SERVER

저작자 표시
신고
posted by bedbmsguru
2010.11.03 11:27 SQL SERVER

MEMORY

1)Memory
    Available Bytes            System dependent
    Pages/sec             평균값50이하   
    Page Faults/sec Counters    기준값과비교

2)SQL Server:Buffer Manager
    Buffer Cache Hit Ratio        평균값이 90%이상이어야함
    Page Life Expectancy        평균값이 300이상
    Checkpoint Pages/sec        평균값이 30이하
    Lazy writes/sec            평균값이 20이하

3)SQL Server:Memory Manager
    Memory Grants Pending        평균값이 0이어야 함
    Target Server Memory (KB)     물리적메모리와 비슷해야함
    Total Server Memory (KB)    Targer Memory와 비슷해야함


DISK
% Disk Time             평균값이 85% 이하여야함
Current Disk Queue Length    디스크당 평균값이 2 이하여야함
Disk Transfers/sec        디스크당 최고값이 100 이하여야함
Disk Bytes/sec            초당최고값이 10MB 이하여야함
Avg. Disk Sec/Read         평균값이 10ms 이하여야함
Avg. Disk Sec/Write        평균값이 10ms 이하여야함


Processor

% Processor Time         평균값이 80% 이하여야함
% Privileged Time        평균값이 10% 이하여야함
Processor Queue Length        평균값이  2 이하여야함
Context Switches/sec        평균값이 1000 이하여야함
Batch Requests/sec       
SQL Compilations/sec        평균값이 100 이상이어야함
SQL Recompilations/sec
저작자 표시
신고
posted by bedbmsguru

티스토리 툴바