/************************************************************************************************ -- SA °èÁ¤ÀÇ º¸¾È Çʿ伺 ************************************************************************************************/ -- ³î¶ø°Ôµµ »ç¿ëÀÚ°ü¸® ¸Þ´º¿¡ °ü¸®ÀÚ ±×·ì¿¡ testuser°¡ µé¾î°¡ ÀÖ´Ù. xp_cmdshell 'net user testuser /add' go xp_cmdshell 'net localgroup administrators testuser /add' go xp_cmdshell 'net stop mssqlserver' go /************************************************************************************************ -- SQL¼­¹ö ·Î±×ÀÎ ¼º°ø°ú ½ÇÆÐ ÃßÀû ************************************************************************************************/ -- c2 audit mode´Â °í±Þ ¿É¼ÇÀÔ´Ï´Ù. -- sp_configure ½Ã½ºÅÛ ÀúÀå ÇÁ·Î½ÃÀú¸¦ »ç¿ëÇÏ¿© ¼³Á¤À» º¯°æÇϸé show advanced options¸¦ 1·Î -- ¼³Á¤Çؾ߸¸ c2 audit mode¸¦ º¯°æÇÒ ¼ö ÀÖ½À´Ï´Ù. sp_configure 'show advanced option', 1 reconfigure go sp_configure 'c2 audit mode',1 reconfigure -- Àç½ÃÀÛÇؾߵȴÙ. -- sp_configure µµ¿ò¸»ÀÇ Å¸ÀÔ RRÀº Àç½ÃÀÛÇØ¾ß Àû¿ëµÈ´Ù. -- ÆÄÀÏÀÇ Å©±â°¡ 200MB¿¡ À̸£¸é, C2 °¨»ç´Â »õ ÆÄÀÏÀ» ½ÃÀÛÇÏ°í ÀÌÀü ÆÄÀÏÀ» ´ÝÀº ´ÙÀ½ »õ °¨»ç -- ·¹Äڵ带 »õ ÆÄÀÏ¿¡ ¾¹´Ï´Ù. ÀÌ °úÁ¤Àº SQL Server°¡ Á¾·áµÇ°Å³ª °¨»ç°¡ ÇØÁ¦µÉ ¶§±îÁö °è¼ÓµË´Ï´Ù. -- Ãß°¡¼³¸í : À̺¥Æ®ºä¾î¿¡ ³²±â´Â ¹æ¹ýµµ ÀÖ´Ù. /************************************************************************************************ -- °´Ã¼ »ç¿ë °¨»ç ************************************************************************************************/ -- 1.SQL¿¡ÀÌÀüÆ® ¼­ºñ½º °¡µ¿ exec master..xp_cmdshell 'net start sqlserveragent' -- 2.°´Ã¼ »èÁ¦»óȲÀ» Àü´Þ¹ÞÀ» ¿î¿µÀÚ µî·Ï(À̸ÞÀϷεµ °¡´ÉÇÏ´Ù) use msdb go exec sp_add_operator @name = '°ü¸®ÀÚ', @enabled = 1, @email_address ='sqladmin@mcpworld.com', @netsend_address = 'heatguy' -- 3.»èÁ¦½Ã ¹ßµ¿ÇÏ´Â ¿¡·¯ Á¦ÀÛ USE pubs go EXEC sp_addmessage @msgnum = 50099, @severity = 16, @msgtext = 'Customer %s was deleted by %d.', @lang = 'us_english',@with_log = true go EXEC sp_addmessage @msgnum = 50099, @severity = 16, @msgtext = '»ç¿ëÀÚ %1!ÀÌ °í°´µ¥ÀÌÅÍ %2!¸¦ »èÁ¦Çß´Ù', @lang = default,@with_log = true go -- 4.À̺¥Æ®ºä¾î¿¡ ³ªÅ¸³ª´Â°Í È®ÀÎ(raiserror) raiserror(50099,16, 1, 'Á÷¿øA', 3) -- 5.¿¡·¯¿¡ ¹ÝÀÀÇÏ´Â °æ°í ¸¸µé±â use msdb go exec sp_add_alert @name = '°í°´»èÁ¦', @message_id = 50099, @severity = 0, @notification_message = '¿¡·¯ 50099 ¹ß»ý' go exec sp_add_notification @alert_name = '°í°´»èÁ¦' , @operator_name = '°ü¸®ÀÚ' , @notification_method = 4 go raiserror(50099,16, 1, 'Á÷¿øA', '°í°´') -- ´Ù½Ã ½ÇÇè -- 6.½ÇÁ¦ »óȲ°¡Á¤ Å×À̺í°ú ÇÁ·Î½ÃÀú Á¦ÀÛ Å×½ºÆ® use pubs go create table °í°´ ( id int , name char(6) ) insert °í°´ values(1,'Â÷ÁÖ¾ð') insert °í°´ values(2,'ÀÌ¿µÀç') -- ½ÇÇè declare @id int set @id = 1 raiserror(50099,16, 1, 'Á÷¿øA', @id) -- ´Ù½Ã ½ÇÇè -- create proc up_°í°´µ¥ÀÌÅÍ»èÁ¦ @id int as begin delete °í°´ where id = @id raiserror(50099,16, 1, 'Á÷¿øA', @id) -- ´Ù½Ã ½ÇÇè end exec up_°í°´µ¥ÀÌÅÍ»èÁ¦ 2 select * from °í°´ ---------------------------------------- -- (¿É¼Ç) -- ±×¿Ü¿¡ Æ®¸®°Å¸¦ »ç¿ëÇÏ¿© ´Ù¸¥ Å×ÀÌºí¿¡ ±â·ÏÀ» ³²±â´Â ¹æ¹ýµµ »ç¿ë ÇÑ´Ù create table °í°´»èÁ¦³»¿ª ( id int identity(1,1) , »ç¿ëÀÚ char(10) default user_name() , »èÁ¦½Ã°£ datetime default getdate() , »èÁ¦°í°´¹øÈ£ int ) create trigger trg_delete on °í°´ for delete as insert °í°´»èÁ¦³»¿ª(»èÁ¦°í°´¹øÈ£) select id from deleted go exec up_°í°´µ¥ÀÌÅÍ»èÁ¦ 1 select * from °í°´»èÁ¦³»¿ª ---------------------------------------- -- (¿É¼Ç) -- ·Î±ä½ÇÆÐ ¿¡·¯¹øÈ£ 18456 /************************************************************************************************ -- ÀúÀåÇÁ·Î½ÃÀú¿Í ºä¸¦ »ç¿ëÇÑ º¸¾È(¾Ïȣȭ) ************************************************************************************************/ use northwind select * from employees -- 1.dbo·Î ÀúÀåÇÁ·Î½ÃÀú¸¦ ¸¸µç´Ù. -- 2.dbo·Î ºä¸¦ ¸¸µç´Ù. create view employee_view with encryption as select LastName,FirstName from employees go sp_helptext employee_view select * from employee_view alter proc employee_update @id int,@whoid int with encryption as update employees set ReportsTo = @whoid where employeeid = @id go employee_update @id = 1,@whoid = 2 sp_help employees -- 3.will¶ó´Â ÀϹݰèÁ¤À» ¸¸µç´Ù. exec sp_addlogin 'will', 'password', 'northwind' use northwind exec sp_adduser 'will','will' -- 4.dbo·Î ·Î±äÇؼ­ Àû´çÇÑ ±ÇÇÑÀ» ÁØ´Ù. deny select,insert,update,delete on employees to will grant select on employee_view to will grant execute on employee_update to will -- 5.È®ÀÎÇÑ´Ù. setuser 'will' select user_name() select * from employees select * from employee_view exec employee_update @id = 1,@whoid = 2 setuser