-- XML 의 exist 메소드를 활용 사례
--  : XML 문서에서 어떤 속성의 특정값이 존재하는지를 검사
-- (only SQL Server 2005)
DECLARE @v_xml XML
SELECT @v_xml = N'<rows><row id="1" tag="1"/><row id="1" tag="0"/></rows>'

--rows/row/@tag속성의 값이 1인 엘리멘트가 존재하지를 반환
SELECT @v_xml.exist('rows/row[@tag="1"]')   result
---존재함
---result = 1  

SELECT @v_xml.exist('rows/row[@tag="2"]')   result
---존재하지 않음
---result = 0

출처 : 직접 작성.

이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 좐군

2010/02/11 23:16 2010/02/11 23:16
, , , ,
Response
No Trackback , No Comment
RSS :
http://John.tobe30.com/tc/rss/response/297

Trackback URL : http://John.tobe30.com/tc/trackback/297

Leave a comment
[로그인][오픈아이디란?]
DECLARE @old_datefirst INT
SELECT @old_datefirst = @@DATEFIRST

DECLARE @v_dayname_monday INT
SELECT @v_dayname_monday = 1
SET DATEFIRST @v_dayname_monday

DECLARE @v_date DATETIME
SELECT @v_date = '2009-08-01'    ---특정 날짜 지정.

SELECT @v_date date
, DATEPART(year, @v_date) [Year]
, DATEPART(week, @v_date) [Week of Year]
, DATEPART(dayofyear, @v_date) [Day of Year]
, CASE
WHEN DATEPART(weekday, @v_date) > 1 THEN DATEADD(day, (DATEPART(weekday, @v_date)-1) * -1 , @v_date)
ELSE @v_date END [First-day of Week]
, CASE
WHEN DATEPART(weekday, @v_date) < 7 THEN DATEADD(day, 7-DATEPART(weekday, @v_date), @v_date)
ELSE @v_date END [Last-day of Week]

SET DATEFIRST @old_datefirst

/*
실행결과
date                 Year Week of Year Day of Year First-day of Week   Last-day of Week
2009-08-01 2009 31                         213                 2009-07-27            2009-08-02
*/
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 좐군

2009/08/20 22:00 2009/08/20 22:00
, ,
Response
No Trackback , No Comment
RSS :
http://John.tobe30.com/tc/rss/response/189

Trackback URL : http://John.tobe30.com/tc/trackback/189

Leave a comment
[로그인][오픈아이디란?]

SQL Injection Tools 3가지

SQL Injection : 일반적으로 데이터베이스에 접근하는 어플리케이션에서 SQL문에 대한 문자열 필터링을 하지 않고 바로 데이터베이스로 넘기는 것이 가능한 점을 이용한 Exploit 방법의 일종이다. 

v_user_id = Request("user_id")
v_pwd     = Request("pwd")
strsql    = "select * from user where user_id =' " + v_user_id + " ' AND pwd=' " + v_pwd + " ' "
Set rs = adoConn.execute(strsql)
If Rs.Eof Then
        --Failure
Else
--Success
End If
위 코드는 user 테이블에 한행이상이 존재하고 만일 pwd값에 ' or 1=1 or ''=' 입력되었다면 항상 Success로 실행되게 된다. 다음 SQL문이 실제 실행되게 된다.
select * from user where user_id ='1111' AND pwd='' or 1=1 or ''=''

다음 SQL Injection Tool들 이다.

HP Scrawlr—This free scanner utility can detect and identify whether your website is susceptible to an SQL injection attack. The utility crawls a website, analyzing the entry fields of each web page for SQL injection vulnerabilities as it goes. (Note that it doesn’t work against JavaScript, flash parsing, or POST parameters.) You can learn more about HP Scrawlr at http://www.communities.hp.com/securitysoftware/blogs/spilabs/archive/2008/06/23/finding-sql-injection-with-scrawlr.aspx

URLScan—This security tool actively restricts the kind of HTTP requests that Microsoft IIS will process. URLScan isn’t a substitute for properly programming a web application, but it can prevent some potentially harmful requests from reaching the web application and SQL Server. It works on IIS 5.1 and later, including IIS 7.0 for Windows Server 2008. For more information about URLScan.
http://learn.iis.net/page.aspx/473/using-urlscan.

Microsoft Source Code Analyzer for SQL Injection—This command-line tool analyzes your static ASP source code written in VBScript (not ASP.NET) and reveals possible vulnerabilities to SQL injection attacks. The tool then generates a report detailing the vulnerabilities it detected and possible remedies. Microsoft Source Code Analyzer for SQL Injection is available at http://www.microsoft.com/downloads/details.aspx?FamilyId=58A7C46E-A599-4FCB-9AB4-A4334146B6BA&displaylang=en.
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 좐군

2009/01/16 06:40 2009/01/16 06:40

Trackback URL : http://John.tobe30.com/tc/trackback/68

Leave a comment
[로그인][오픈아이디란?]

[SQL]간단한 TREE 구조 구현

/*[테이블설계]*/

CREATE TABLE TreeMenu(
menu_cd int , --메뉴코드
menu_nm varchar(50) , --메뉴명
parent_cd int , --상위메뉴코드
CONSTRAINT PK_TreeMenu PRIMARY KEY (menu_cd)
)

/*[샘플데이터]*/
insert into TreeMenu VALUES(1, '시작'	   , 0)
insert into TreeMenu VALUES(2, '프로그램'	   , 1)
insert into TreeMenu VALUES(3, '설정' , 1) insert into TreeMenu VALUES(4, '보조프로그램', 2)
insert into TreeMenu VALUES(5, '제어판' , 3) insert into TreeMenu VALUES(6, '네트워크환경', 5)
insert into TreeMenu VALUES(7, '계산기' , 4) insert into TreeMenu VALUES(8, '그림판' , 4)
GO

/*[핵심함수 구현]*/
/***********************************************
트리구조에서 각 노드(행)의 절대위치를 Binary계산하는 함수
최대 64 Level 지원 ***********************************************/
go
CREATE FUNCTION FN_TreeOrderBy(
@root int, /*루트값*/
@menu_cd int /*현재값*/
) RETURNS varbinary(256)
BEGIN
DECLARE @parent_cd int ,
@level_bin varbinary(256)
IF @menu_cd = @root
BEGIN
RETURN 0
END
select @level_bin = CAST(@menu_cd AS varbinary(4)) --값 초기화
/*루프로 menu_cd위 절대위치 계산*/
WHILE 1 = 1
BEGIN
SELECT @parent_cd = parent_cd
FROM TreeMenu WITH(NOLOCK)
WHERE menu_cd = @menu_cd
IF (@root=@parent_cd or @parent_cd=0 or @parent_cd is null)
BEGIN
BREAK
END
SELECT @menu_cd = @parent_cd
SELECT @level_bin = CAST(@parent_cd AS varbinary(4)) + @level_bin
END
RETURN @level_bin
END
go

/*[함수사용하여 조회]*/
SELECT 	a.*	,
dbo.FN_TreeOrderBy(1, a.menu_cd) absolute_pos
FROM TreeMenu A WITH(NOLOCK)
ORDER BY absolute_pos --계산된 열로 정열
/*
속도를 더 빨리 하기 위한 방법으로는 삭제/수정/등록시
절대위치(absolute_pos)를 계산해서 저장하는 방법입니다. 저장된 절대위치에 클러스트인덱스 설정하면 검색속도가 더욱 빠릅니다
그래도
대용량 쿼리할 때 이용하기엔 쫌 부담이 되겠네요 -ㅅ-
*/
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 좐군

2008/12/19 23:15 2008/12/19 23:15
, , ,
Response
No Trackback , No Comment
RSS :
http://John.tobe30.com/tc/rss/response/39

Trackback URL : http://John.tobe30.com/tc/trackback/39

Leave a comment
[로그인][오픈아이디란?]
DECLARE    @cursor   CURSOR
,	@sql	NVARCHAR(1000)
,	@params	NVARCHAR(100)
DECLARE @id	INT
,	@name	NVARCHAR(200)

SELECT	@sql =N'SET @p_cur = CURSOR FORWARD_ONLY READ_ONLY FOR 
	SELECT top 10 id, name FROM dbo.sysobjects WITH(NOLOCK) WHERE id < 10;
	OPEN @p_cur'
SELECT	@params = N'@p_cur CURSOR OUTPUT'

EXEC sp_executesql
	@sql
,	@params
,	@p_cur	= @cursor	OUTPUT


FETCH NEXT FROM @cursor INTO @id, @name WHILE (@@FETCH_STATUS=0) BEGIN PRINT CAST(@id AS VARCHAR(10)) + ':' + @name FETCH NEXT FROM @cursor INTO @id, @name END CLOSE @cursor DEALLOCATE @cursor
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 좐군

2008/12/18 23:07 2008/12/18 23:07
, , ,
Response
No Trackback , No Comment
RSS :
http://John.tobe30.com/tc/rss/response/38

Trackback URL : http://John.tobe30.com/tc/trackback/38

Leave a comment
[로그인][오픈아이디란?]

DB복원-시간을 지정하여 복원하기

시간을 지정하여 복원하려면

  1. NORECOVERY 옵션을 사용하여 RESTORE DATABASE 문을 실행합니다.
  2. RESTORE LOG 문을 실행하여 각 로그 백업을 적용하며 다음을 지정합니다.
    • 트랜잭션 로그가 적용될 데이터베이스의 이름
    • 트랜잭션 로그 백업을 복원하는 백업 장치
    • RECOVERY 및 STOPAT 옵션. 지정된 시간이 트랜잭션 로그에서 수용하는 시간을 초과하는 경우와 같이 트랜잭션 로그 백업이 요청한 시간을 포함하지 않을 경우 경고가 생성되고 데이터베이스는 복구되지 않은 상태로 남습니다.

다음 예에서는 AdventureWorks 데이터베이스를 12:00 AM on April 15, 2005 현재의 상태로 복원합니다. 복원 시퀀스에서는 NORECOVERY 옵션을 사용하여 전체 데이터베이스 백업을 설치하고 3개의 로그 백업을 적용하며 각 RESTORE LOG 문에 RECOVERYSTOPAT 옵션을 지정합니다. 백업 장치는 AdventureWorksBackups라는 논리적 백업 장치입니다.

중요:
AdventureWorks 데이터베이스는 단순 복구 모델을 사용합니다. 로그 백업을 허용하려면 전체 데이터베이스 백업을 수행하기 전에 ALTER DATABASE AdventureWorks SET RECOVERY FULL을 사용하여 데이터베이스에서 전체 복구 모델을 사용하도록 설정해야 합니다.

-- Restore the full database backup.
RESTORE DATABASE AdventureWorks
   FROM AdventureWorksBackups 
   WITH NORECOVERY;
GO
RESTORE LOG AdventureWorks
   FROM AdventureWorksBackups
   WITH RECOVERY, STOPAT = 'Apr 15, 2005 12:00 AM';
GO
RESTORE LOG AdventureWorks
   FROM AdventureWorksBackups
   WITH RECOVERY, STOPAT = 'Apr 15, 2005 12:00 AM';
GO
RESTORE LOG AdventureWorks
   FROM AdventureWorksBackups
   WITH RECOVERY, STOPAT = 'Apr 15, 2005 12:00 AM';
   GO 

원문 : http://msdn.microsoft.com/ko-kr/library/ms179451(SQL.90).aspx
이올린에 북마크하기(0) 이올린에 추천하기(0)

Posted by 좐군

2008/11/14 02:40 2008/11/14 02:40
, , , , ,
Response
No Trackback , No Comment
RSS :
http://John.tobe30.com/tc/rss/response/9

Trackback URL : http://John.tobe30.com/tc/trackback/9

Leave a comment
[로그인][오픈아이디란?]