RSS구독하기:SUBSCRIBE TO RSS FEED
즐겨찾기추가:ADD FAVORITE
글쓰기:POST
관리자:ADMINISTRATOR
'분류 전체보기'에 해당되는 글 379
http://bada.kldp.net/projects/modurl/

가서 최신 버젼을 받고

shell> apxs -i -c mod_url.c

또는 소스 디렉토리에 GNUMakefile 이 존재 한다면

shell> make
를 한다.


apxs 가 없을때는 아래에 링크를 따라가라.
http://comefeel.com/tt/comefeel/entry/%EC%9A%B0%EB%B6%84%ED%88%AC%EC%97%90%EC%84%9C-apxs-%EC%93%B0%EB%8A%94%EB%B2%95?category=14



그리고

vi /etc/apache2/mods-enabled/url.conf 해주고 아래 내용 기입
<IfModule mod_url.c>
   CheckURL On
   ServerEncoding EUC-KR
   ClientEncoding UTF-8
</IfModule>

vi /etc/apache2/mods-enabled/url.load 해주고 아래 내용 기입
LoadModule  userdir_module   /usr/lib/apache2/modules/mod_userdir.so
LoadModule  redurl_module    /usr/lib/apache2/modules/mod_url.so

아파치 리스타트

끗.
2011/02/15 12:23 2011/02/15 12:23
이 글에는 트랙백을 보낼 수 없습니다
dpkg -l |grep apache2

해보고

apache2-threaded-dev 있으면
sudo apt-get remove apache2-threaded-dev 제거 해주고

sudo apt-get install apache2-prefork-dev 설치로 마무리.


끗 -_-;
2011/02/15 10:59 2011/02/15 10:59
이 글에는 트랙백을 보낼 수 없습니다
어셈블리 인증 때문에 컴파일은 정상적으로 이루어지나,  MSB3073 오류 가 발생하는 것은

MSRDS 2008을 설치 하면 어셈블리 인증에 필요한 key 파일(mrisamples.snk)이  

\Microsoft Robotics Dev Studio 2008\samples 에 mrisamples.snk이 자동 위치해 있다.

samples 폴더 밑에 있는 mrisamples.snk를 다음의 경로에 옮겨 놓자.

\Microsoft Robotics Dev Studio 2008\bin

그리고 Properties에서 mrisamples.snk의 경로를 지정해 주자.

2011/01/07 11:36 2011/01/07 11:36
이 글에는 트랙백을 보낼 수 없습니다

최저 20기가(20기가 이하는 설정하더라도 resize버튼이 활성화 되지 않습니다.) 최대 4테라바이트까지 줄이거나 늘릴 수 있습니다.

Dynamic과 Fixed로 타입을 정할 수 있고, 용량을 설정할 수 있습니다.

Dynamic(동적)은 VHD의 사용용량만큼만 사용해서 파일로 존재하다가 마운트 및 부팅 시 최대용량으로 동작하는 것이고, Fixed(고정)은 VHD의 실 사용용량과는 별개로 전체용량으로 항상 존재하게 하는 방법입니다.

일반적인 VHD를 생성해서 사용할 때는 상관없지만, VHD형태로 배포되는 파일의 최대용량을 줄일 수 있는 유용한 유틸입니다.


2010/12/15 16:41 2010/12/15 16:41
이 글에는 트랙백을 보낼 수 없습니다

We've added to ChartServer a few chart types to let you easily draw advanced map pins. You can use these with the Google Maps API to add pins to your maps, or for any other application. The rotated map pins can be useful for indicating clusters of locations.

ChartServer에 지도 마커의 핀 이미지를 그리게 하는 몇 가지 차트 타입을 추가해 왔다. 이것들을 통하여 Google Maps API를 이용한 지도나, 다른 어떤 어플리케이션에 핀 이미지를 추가할 수 있다. 기울여진 맵 핀은 장소들의 클러스터링 된 것을 인지시켜줄 때 유용하다.

Standard map pin with a letter inside

글씨가 들어가 있는 기본적인 맵 핀


To get a standard map pin with a letter inside, use an URL like

http://www.google.com/chart?chst=d_map_pin_letter&chld=A|FF0000|000000 

The chld URL argument contains several components separated by "|". The meaning of each component is:

chld URL인자는 "|"로 분리된 여러 개의 인자를 포함한다. 각각의 컴포넌트의 의미는 다음과 같다.

  1. letter to put in the map pin, for example A, b, or 9. This must be in UTF-8, and then URL-escaped, so, for example, to get a space you must type +, to get a plus sign you must type %2B, to get љ you must type %D1%99, and to get 駅 you must type %E9%A7%85.
    맵 핀에 넣어질 글씨  A, b, 또는 9. 이것은 반드시 UTF-8로 인코딩 되어야 하고, URL-escape되어져야 한다. 따라서 예를 들면 공백을 넣으려면 + 를 타이핑해라, 플러스 기호를 얻으려면  %2B,  љ 는 %D1%99,  駅 는 %E9%A7%85를 타이핑 해라.
    이 그림과 같이 a와 공백 그리고  +를 넣으려면
    http://www.google.com/chart?chst=d_map_pin_letter&chld=a+%2B|FF0000|000000
  2. pin fill color, as a 6-digit hexadecimal number, for example 000000 for black, FF0000 for red, FFFFFF for white, or FFFF00 for yellow.
    핀을 채울 컬러. 6자리 핵사 코드 
  3. text color, also as a 6-digit hexadecimal number.
    글자의 색깔, 6자리 핵사 코드

Standard map pin with an icon inside
아이콘이 들어가 있는 기본 맵 핀

To get a standard map pin with an icon inside, use an URL like
아이콘이 들어가 있는 기본 맵 핀을 얻으려면 URL을 다음과 같이 사용해라.

http://www.google.com/chart?chst=d_map_pin_icon&chld=home|FFFF00

The chld URL argument contains several components separated by "|". The meaning of each component is:
chld URL 인자는 "|"로 분리된 몇개의 인자를 포한한다. 각각의 컴포넌트의 의미는

  1. icon to put in the map pin. See here for the list of valid icon names.
    맵 핀에 넣을 icon . 여기에 가능한 아이콘 이름 리스트가 있다.
  2. pin fill color, as a 6-digit hexadecimal number, for example 000000 for black, FF0000 for red, FFFFFF for white, or FFFF00 for yellow.
    핀을 채울 컬러. 6자리 핵사 코드

Map pin with advanced shape and a letter inside
문자와 추가 쉐이프를 가진 맵핀

To get a map pin with an advanced shape and a letter inside, use an URL like
문자와 추가 쉐이프를 가진 맵핀을 생성하는 URL은 다음과 같다.

http://www.google.com/chart?chst=d_map_xpin_letter&chld=pin_star|A|00FFFF|000000|FF0000

The chld URL argument contains several components separated by "|". The meaning of each component is:
chld URL 인자는 "|"로 분리된 몇개의 인자를 포한한다. 각각의 컴포넌트의 의미는

  1. shape to use for the map pin. The valid shape names are: pin for a normal pin, pin_star for a pin with a star, pin_sleft for a left-leaning pin, and pin_sright for a right-leaning pin.
    맵핀에 사용되어질 shape. 가능한 쉐이프 이름은 pin 기본 핀, pin_star 별모양 핀, pin_sleft 왼쪽으로 기울여진 핀,  pin_sright 오른쪽으로 기울여진 핀.
  2. letter to put in the map pin, for example A, b, or 9. This must be in UTF-8, and then URL-escaped, so, for example, to get a space you must type +, to get a plus sign you must type %2B, to get љ you must type %D1%99, and to get 駅 you must type %E9%A7%85.
    맵 핀에 넣어질 글씨  A, b, 또는 9. 이것은 반드시 UTF-8로 인코딩 되어야 하고, URL-escape되어져야 한다. 따라서 예를 들면 공백을 넣으려면 + 를 타이핑해라, 플러스 기호를 얻으려면  %2B,  љ 는 %D1%99,  駅 는 %E9%A7%85를 타이핑 해라
  3. pin fill color, as a 6-digit hexadecimal number, for example 000000 for black, FF0000 for red, FFFFFF for white, or FFFF00 for yellow.
    핀을 채울 컬러. 6자리 핵사 코드 
  4. text color, also as a 6-digit hexadecimal number.
    문자를 채울 컬러. 6자리 핵사 코드 
  5. star fill color, also as a 6-digit hexadecimal number. This is only used for the pin_star pin shape. For other shapes, just use 0.
    별 모양을 채울 컬러, 6자리 핵사 코드. 이것은  핀 모양 옵션이 pin_star 일 때만 사용, 다른 모양을 위해서는 그냥  0을 사용

Map pin with advanced shape and an icon inside
추가 쉐이프와 아이콘을 가진 맵핀

To get a map pin with an advanced shape and a letter inside, use an URL like
추가 쉐이프와 글자를 가진 맵 핀을 생성하려면 URL은 다음과 같다.

http://www.google.com/chart?chst=d_map_xpin_icon&chld=pin_star|home|00FFFF|FF0000

The chld URL argument contains several components separated by "|". The meaning of each component is:
chld URL 인자는 "|"로 분리된 몇개의 인자를 포한한다. 각각의 컴포넌트의 의미는

  1. shape to use for the map pin. The valid shape names are: pin for a normal pin, pin_star for a pin with a star, pin_sleft for a left-leaning pin, and pin_sright for a right-leaning pin.
    맵핀에 사용되어질 shape. 가능한 쉐이프 이름은 pin 기본 핀, pin_star 별모양 핀, pin_sleft 왼쪽으로 기울여진 핀,  pin_sright 오른쪽으로 기울여진 핀. 
  2. icon to put in the map pin. See here for the list of valid icon names.
    맵 핀에 넣을 icon . 여기에 가능한 아이콘 이름 리스트가 있다. 
  3. pin fill color, as a 6-digit hexadecimal number, for example 000000 for black, FF0000 for red, FFFFFF for white, or FFFF00 for yellow.
    핀을 채울 컬러. 6자리 핵사 코드
  4. star fill color, also as a 6-digit hexadecimal number. This is only used for the pin_star pin shape. For other shapes, just use 0.
    별 모양을 채울 컬러, 6자리 핵사 코드. 이것은  핀 모양 옵션이 pin_star 일 때만 사용, 다른 모양을 위해서는 그냥  0을 사용

Map pin with text inside, scaling, and rotation
텍스트와 , 스케일, 회전각을 가진 맵핀

To get a map pin with text inside, scaling, and rotation, use an URL like
텍스트오 , 스케일, 회전각을 가진 맵 핀을 얻으려면 URL은 다음과 같다.

http://www.google.com/chart?chst=d_map_spin&chld=1.2|30|FFFF88|10|_|foo|bar

The chld URL argument contains several components separated by "|". The meaning of each component is:
chld URL 인자는 "|"로 분리된 몇개의 인자를 포한한다. 각각의 컴포넌트의 의미는

  1. scale factor for the map pin. A positive decimal number; the larger it is, the larger the map pin will be. For example, 0.5, 1, or 2.2. 스케일 값이 0.5 이면 스케일 되지 않은 핀의 will give you a map pin of the same size as the non-scaled pins, in case you only want to have rotation.
    맵 핀을 위한 scale factor . 양수의 decimal 숫자. 숫자가 클수록 맵 핀이 커질 것이다. 예를 들어 0.5, 12.2. scale factor 0.5  값은 스케일 되지 않은 기본 핀의 크기와 같다.(1이 아니라는 것을 주의 ), 이 때는 단지 너가 회전만을 원한다고 생각한다.
  2. rotation for the map pin, in degrees, counting counter-clockwise; you can use negative or positive numbers. For example, 30, -45, or 270. If you don't want any rotation, use 0.
    맵 핀의  rotation , 각도 단위, 반시계 방향. 양수 음수 모두 사용가능. 예를 들면  30, -45, or 270. 회전각을 원하지 않으면 0을 사용. 
  3. pin fill color, as a 6-digit hexadecimal number, for example 000000 for black, FF0000 for red, FFFFFF for white, or FFFF00 for yellow.
    핀을 채울 컬러. 6자리 핵사 코드
  4. font size for the text in the map pin, in pixels. For example, 10, 12, or 16.
    맵 핀의 font size . 예를 들어 10, 12, 16.
  5. font style for the text in the map pin: _ for normal text and b for boldface.
    맵 핀 텍스트의 font style: _ 는 기본 텍스트 b 는 굵은 글씨체.  
  6. text, one or more "|"-separated component in the URL. Each component will be written as a different line, from top to bottom. Each component must be in UTF-8, and then URL-escaped, so, for example, to get a space you must type +, to get a plus sign you must type %2B, to get љ you must type %D1%99, and to get 駅 you must type %E9%A7%85.
    맵 핀에 넣어질 글씨  A, b, 또는 9. 이것은 반드시 UTF-8로 인코딩 되어야 하고, URL-escape되어져야 한다. 따라서 예를 들면 공백을 넣으려면 + 를 타이핑해라, 플러스 기호를 얻으려면  %2B,  љ 는 %D1%99,  駅 는 %E9%A7%85를 타이핑 해라

Shadow of a map pin
맵 핀의 그림자

If you want to use these images with the Maps API, you will need to be able to draw their shadows, too.
Maps API와 이미지를 사용할 경우, 맵 핀의 그림자도 필요할 것이다.

Standard map pins
기본 맵 핀

To get the shadow of a standard map pin, i.e. a pin with d_map_pin_letter or d_map_pin_icon, use an URL like
기본 맵핀의 그림자를 얻기 위해서는 , 예를 들어 d_map_pin_letter 혹은 d_map_pin_icon의 URL은 다음과 같다.

http://www.google.com/chart?chst=d_map_pin_shadow

There is no chld URL argument.
chld URL 인자가 없다.

Map pins with an advanced shape

To get the shadow of a map pin with an advanced shape, i.e. a pin with d_map_xpin_letter or d_map_xpin_icon, use an URL like
추가 쉐이프를 가진 맵 핀의 그림자를 얻기 위해서는 , 예를 들어 d_map_xpin_letter 혹은 d_map_xpin_icon,의 URL은 다음과 같다.

http://www.google.com/chart?chst=d_map_xpin_shadow&chld=pin_star

The chld URL argument contains one component:
chld URL 인자는 하나의 컴포넌트를 포함한다.

  1. shape to use for the map pin. The valid shape names are: pin for a normal pin, pin_star for a pin with a star, pin_sleft for a left-leaning pin, and pin_sright for a right-leaning pin.
    맵핀에 사용되어질 shape. 가능한 쉐이프 이름은 pin 기본 핀, pin_star 별모양 핀, pin_sleft 왼쪽으로 기울여진 핀,  pin_sright 오른쪽으로 기울여진 핀. 

Map pins with scaling and rotation

It is not possible to get the shape of a scaled and rotated map pin, i.e. a pin with d_map_spin.

List of valid pin icon names
유효한 핀 아이콘 이름의 목록

These are the icon names that you can use instead of home for the map pins with d_map_pin_icon and d_map_xpin_icon:

WC
WCfemale
WCmale
accomm
airport
baby
bar
bicycle
bus
cafe
camping
car
caution
cinema
computer
corporate
dollar
euro
fire
flag
floral
helicopter
home
info
landslide
legal
location
locomotive
medical
mobile
motorcycle
music
parking
pet
petrol
phone
picnic
postal
pound
repair
restaurant
sail
school
scissors
ship
shoppingbag
shoppingcart
ski
snack
snow
sport
swim
taxi
train
truck
wheelchair
yen

2010/08/25 02:23 2010/08/25 02:23
이 글에는 트랙백을 보낼 수 없습니다
proc : 프로시저
  • oracle
BEGIND 프로시저명(:name, :name2, :name3); END;
  • mssql
자동으로 prepare 적용 
  • mysqli (since mysql 5.0)
call proc_php_test(?, @out); 

select @out;
  • cubrid
select 1 into a from db_root;  -- output 변수 설정 

call proc_php_test(?, ?, ?, a);

select a from db_root; -- output 변수 출력

[편집] select : 조회

  • oracle
select * from 테이블;
  • mssql
select * from 테이블;
  • mysql
select * from 테이블;
set @age := 10;

select @name1 := name1, @name2 := name2 from 테이블 where age = @age;
  • mysqli
select * from 테이블;
  • postgres
select * from 테이블; 
  • cubrid
select * from 테이블;

[편집] insert : 입력

insert 구문을 DB에 따라 다르게 생성한다.

  • oracle
insert into 테이블 values (:name1, :name2, :name3);
  • mssql (자체 구현) - sp_executesql 을 사용하여 구현
insert into 테이블 values (@name1, @name2, @name3);
declare @sql nvarchar(1000)
declare @param nvarchar(1000)

set @sql = N'insert into 테이블 values (@name1, @name2, @name3) '
set @param = N'@name1 varchar(30), @name2 varchar(30), @name3 varchar(30)'

exec sp_executesql @sql, @param, @name1 = '안녕', @name2 = '하세요', @name3 = '호박'
declare @name1 varchar(30) 
declare @name2 varchar(30)
declare @name3 varchar(30)

set @name1 = '안녕'
set @name2 = '하세요'
set @name3 = '호박'

insert into 테이블 values (@name1, @name2, @name3);
  • mysql (자체 구현)
set @name1 := '안녕';
set @name2 := '하세요';
set @name3 := '호박';

insert into 테이블 values (@name1, @name2, @name3);
  • mysqli (mysql은 지원하지 않음)
insert into 테이블 values (?, ?, ?);
  • postgres
insert into 테이블 values ($1, $2);
  • cubrid
insert into 테이블 values (?, ?);

[편집] delete

  • oracle
delete from 테이블 where name = :value or name = :value2;
  • mssql (자체 구현) - sp_executesql 을 사용해서 구현
delete from 테이블 where name = @name1 or name = @name2;
declare @sql nvarchar(1000)
declare @param nvarchar(1000)

set @sql = N'delete from 테이블 where name = @name1 or name = @name2; '
set @param = N'@name1 varchar(30), @name2 varchar(30)'

exec sp_executesql @sql, @param, @name1 = '안녕', @name2 = '하세요'
  • mysql (자체 구현)
set @name1 := '안녕';
set @name2 := '하세요';

delete from 테이블 where name = @name1 or name = @name2;
  • mysqli (mysql은 지원하지 않음)
delete from 테이블 where name = ? or name = ?;
  • postgres
delete from 테이블 where name = $1 or name = $2;
  • cubrid
delete from 테이블 where name = ? or name = ?;

[편집] update

  • oracle
update 테이블 set name = :value where name2 = :value2 or name2 = :value3;
  • mssql (자체 구현) - sp_executesql 을 사용하여 구현
update 테이블 set name = @name1 where name2 = @name2 or name2 = @name3;
declare @sql nvarchar(1000)
declare @param nvarchar(1000)

set @sql = N'update 테이블 set name = @name1 where name2 = @name2 or name2 = @name3;'
set @param = N'@name1 varchar(30), @name2 varchar(30), @name3 varchar(30)'

exec sp_executesql @sql, @param, @name1 = '안녕', @name2 = '하세요', @name3 = '메롱'


  • mysql (자체 구현)
set @name1 := '안녕';
set @name2 := '하세요';
set @name3 := '메롱';

update 테이블 set name = @name1 where name2 = @name2 or name2 = @name3;
  • mysqli (mysql 지원하지 않음)
update 테이블 set name = ? where name2 = ? or name2 = ?;
  • postgres
update 테이블 set name = $1 where name2 = $2 or name2 = $3;
  • cubrid
update 테이블 set name = ? where name2 = ? or name2 = ?;
2010/02/22 23:49 2010/02/22 23:49
이 글에는 트랙백을 보낼 수 없습니다
Visual Basic, ASP, VB.NET에서 ADO, ADO.NET을 이용한 Database 프로그램을 개발하는 경우 프로그램내에 SQL 구문을 문자열로 연결한 후 실행하도록 구성한 코드를 많이 보게 된다.

이러한 코드 구성을 일반적으로 '동적 쿼리', '하드 코딩된 쿼리'라 부른다.

예를 들어 비주얼 베이직의 경우

Dim strSQL As String

strSQL="select orderid, orderdate, employeeid from orders"
strSQL=strSQL+" where orderid=" & txtOrderID

cnn.Execute strSQL

하지만 이같은 동적 쿼리는 가능한 사용하지 않는 것이 좋다. 대신 SQL Server의 저장 프로시저를 이용해 처리 용량과 응답 속도의 향상 및 유지 보수 등 저장 프로시저의 특징을 활용하는 것이 좋다.

하지만 설계상의 문제나 또는 고객의 다양한 요구 구현 방법상의 이질적 문제로 인해 동적 쿼리를 써야하는 상황이 자주 발생한다. Q/A의 질문 유형 중에도 이같은 동적 쿼리 작성법에 관한 내용이 상당수를 차지하고 있다.

저 장 프로시저를 통해 코드를 구성하더라도 저장 프로시저 내에서 다시 동적 쿼리를 사용하게 되는 경우가 발생한다. 온라인 설명서에는 이를 '런타임 시 명령문 작성'이라는 주제로 설명했다. 이 경우 SQL Server에서는 sp_executesql, exec()의 두가지 명령을 사용할 수 있다.

클라이언트나 서버 사이드에서 동적 쿼리를 사용해야 하는 상황이 되었을 때, 다시말해 저장 프로시저를 직접 사용할 수 없는 상황에서는 또 다른 해결 방법을 이용할 수 있다.
아래 두 가지 상황에서의 해결 방법이다.

클라인트 사이드에서 동적 쿼리가 필요한 경우

ADO, ADO.NET에서는 파라미터를 가진 동적 쿼리를 지정할 수 있으며 일반적으로 아래와 코드 구성을 가진다.

1. ADO, ODBC, Command 오브젝트 연동
Dim strSQL As String

strSQL="select orderid, orderdate, employeeid from orders"
strSQL=strSQL+" where orderid = ?"

2. ADO.NET, SqlClient 네임스페이스, SqlCommand 오브젝트와 연동
Dim strSQL As String

strSQL="select orderid, orderdate, employeeid from orders"
strSQL=strSQL+" where orderid = @orderid"

위 에 코드를 실행하면 실제 SQL Server에서는 sp_executesql 시스템 프로시저를 통해서 실행이 된다. 특히 ADO.NET의 경우는 디자인 타임에 'SqlDataAdapter Configuration Wizard'를 사용하면 위와 같은 코드를 작성해 준다.

SQL Server, 저장 프로시저에서 동적 쿼리가 필요한 경우
exec() 아니라 sp_executesql 시스템 프로시저를 이용한다.

결 국 클라이언트 사이드건 서버 사이드건 sp_executesql이 사용된 것을 알 수 있다. exec()를 쓴 경우와 sp_executesql를 사용한 경우의 성능과 SQL Server의 Cache 매니저의 상황 비교에 대한 내용을 마지막에 추가해 두었다.

일반적으로 sp_executesql은 exec()비해 몇 가지 장점을 제공한다.

1. 쿼리문안에 매개변수(입력/출력)를 정의할 수 있다.
2. 매개변수 사용으로 인해 쿼리 최적화 프로그램이 컴파일된 실행 플랜을 재 사용할 확률이 높아진다.

실제로 exec()와 sp_executesql은 Cache 매니저의 처리 방법 및 활동 상태가 다르다는 것을 마지막에 추가한 성능 모니터링을 통해서 알 수가 있을 것이다.

이번 기회의 sp_executesql 시스템 프로시저 다양한 사용법과 관련 지식을 얻는데 미력하나마 도움이 됐으면 한다. 그럼, 구문부터 살펴보자.

sp_executesql [@stmt =] stmt
[
{, [@params =] N'@parameter_name data_type [,...n]' }
{, [@param1 =] 'value1' [,...n] }
]

인수설명
@stmt: T-SQL문 또는 배치 명령. ntext 형으로 변환될 수 있는 변수 또는 유니코드 상수 문자열. 내부에 @name 형식의 파라미터를 포함할 수 있다.
@params: @stmt에 포함된 모든 파라미터의 이름과 데이터 타입을 정의한다.
@param1: @params 파라미터에서 첫번째 파라미터에 할당할 값
n : 각 파라미터에 대한 값을 할당한다.

참고
UNICODE 문자열 상수를 지정할 때는 N'...'형식을 사용한다.sp_executesql 프로시저에 선언됐던 파라미터가 ntext형이기 때문에 문자열을 직접 지정할 때는 위와 같은 형태를 사용하면 된다.

sp_executesql은 sql로 구성된 시스템 프로시저가 아니라 확장 프로시저이다.

기본 예제
1. TOP 절의 값을 동적으로 지정하고자 하는 경우(아래 구문은 set rowcount n 세션 옵션으로 대치할 수도 있다)

declare @cnt as nvarchar(5)
declare @stmt as nvarchar(100)
set @cnt = '5'
set @stmt = 'select top ' + @cnt + ' * from northwind.dbo.orders'

exec sp_executesql @stmt

아래 예제는 단순히 SQL을 동적으로 작성하고자 하는 경우로 @db의 값이 실행 시마다
다른 데이터베이스명이 올 수 있다고 가정한다. 테이블명은 동일한다.

declare @db as nvarchar(20)
declare @stmt as nvarchar(100)
set @db = 'northwind'
set @stmt = 'select * from '+ @db +'.dbo.orders'

exec sp_executesql @stmt

2. 하나 이상의 명령을 배치로 실행

declare @stmt as nvarchar(500)
set @stmt = 'use northwind; '
set @stmt = @stmt + 'select top 5 * from dbo.orders where
orderid=10248; '
set @stmt = @stmt + 'select top 5 * from dbo.[order details] where
orderid=10248'

exec sp_executesql @stmt

입력 파라미터를 적용한 예제

1. @orderid 입력 파라미터를 이용해 해당 주문 번호를 가진 [order details] 테이블의 주문 제품 정보를 출력

use northwind

declare @stmt as nvarchar(100)
declare @params as nvarchar(100)
set @stmt = 'select productid, quantity, unitprice from '
set @stmt = @stmt + 'dbo.[order details] where orderid=@orderid'
set @params = '@orderid int'

exec sp_executesql @stmt, @params, @orderid=10248

2. 위 예제를 저장 프로시저 안에서 연동한 경우

use northwind

create proc upOrderDetailsSel
@porderid int
as
declare @stmt as nvarchar(100)
declare @params as nvarchar(100)
set @stmt = 'select productid, quantity, unitprice from '
set @stmt = @stmt + 'dbo.[order details] where orderid=@orderid'
set @params = '@orderid int'

exec sp_executesql @stmt, @params, @orderid=@porderid
go
exec upOrderDetailsSel @porderid = 10248

input 파라미터를 적용한 예제

1. @table을 입력 파라미터를 이용해서 실제 입력할 대상 테이블을 결정 입력될 컬럼값들 또한 입력 파라미터로 처리한 예제

-- 아래 테스트용 테이블을 우선 작성할 것.
create table northwind.dbo.table1 (a int, b int, c int)

use northwind

declare @table as nvarchar(20)
declare @stmt as nvarchar(100)
declare @params as nvarchar(100)

set @table = 'dbo.table1'
set @stmt = 'insert into ' + @table + ' '
set @stmt = @stmt + 'values (@a, @b, @c)'
set @params = '@a int, @b int, @c int'

exec sp_executesql @stmt, @params, @a=1, @b=2, @c=3

확인

select * from table1

2 .output 파라미터를 적용한 예제

동적 SQL문 내에도 출력(OUTPUT) 파라미터를 선언하고 결과 값을 리턴 받을 수 있다. 저장 프로시저에서 출력 파라미터를 사용하는 것과 동일하게, 선언부와 호출부에 반드시 OUTPUT 키워드를 지정한다.

use northwind

declare @stmt as nvarchar(100)
declare @params as nvarchar(100)
declare @orderret as int

set @stmt = 'select @ordercnt = count(*) from dbo.orders'
set @params = '@ordercnt as int OUTPUT' -- OUTPUT 키워드에 주의

여기도 OUTPUT 키워드를 지정한다.

exec sp_executesql @stmt, @params, @ordercnt = @orderret OUTPUT

확인

select @orderret

지원이 안되는 것들은 다음과 같다

*. sp_executesql은 배치, 저장 프로시저, 트리거처럼 한 배치로 실행된다.

1.동적 SQL문에서는 RETURN 문을 사용할 수 없다

2.로컬 변수를 액세스 할 수 없다

declare @chr char(3)
set @chr = 'abc'

sp_executesql N'PRINT @CharVariable'
GO

3. 현재 데이터베이스가 변경되지 않는다
use pubs
go
sp_executesql N'use northwind'
select * from shippers -- shippers 테이블은 northwind에 있다.
go

전문 개발자및 관리자를 위한 추가 정보

성능 비교
만일, 여러분이 Windows NT/2000의 성능 모니터의 사용법을 알고 있다면 아래 3가지 사용 예에 대한 모니터를 수행하고 각각 Cache Manager상의 활동이 어떻게 다른지를 비교 해 보면 많은 도움이 될 것이다.

아래에 성능 모니터에 모니터링할 관련 오브젝트 및 카운트을 적어 뒀다.

성능 개체
SQL Server:Cache Manager
- 모든 카운터
- 다음 목록에서 인스턴스 선택
_Total
Adhoc Sql Plans
Execution Context
Procedure Plans
기타... (관심이 있다면)

참고
3개의 방법을 개별적으로 테스트할 때, Procedure Cache상에 동일한 플랜이 재 사용되는 것을 방지하기 위해

DBCC FREEPROCCACHE

명 령을 사용할 수 있다. 이 명령은 프로시저 캐시에서 모든 요소를 제거한다. 이 작업을 수행해야 Cache Object Counter가 늘어나는 것을 볼 수 있다. 그리고 현재 Cache된 Object에 대한 정보를 보고자 하는 경우 아래의 쿼리를 이용하면 된다.

select * from master..syscacheobjects
where dbid = db_id('northwind')

1. 저장 프로시저 테스트용
DROP PROC dbo.upOrderDetailsQuery
CREATE PROC dbo.upOrderDetailsQuery
@orderid int
AS
select productid, quantity, unitprice from dbo.[order details]
where orderid = @orderid
go
EXEC dbo.upOrderDetailsQuery @orderid = 10248

2. sp_executesql

USE Northwind

declare @stmt as nvarchar(100)
declare @params as nvarchar(100)
set @stmt = 'select productid, quantity, unitprice from '
set @stmt = @stmt + 'dbo.[order details] where orderid=@orderid'
set @params = '@orderid int'

exec sp_executesql @stmt, @params, @orderid=10248
go

3. EXEC() 사용

USE Northwind

declare @stmt as nvarchar(100)
declare @orderid varchar(10)
set @orderid = '10248'
set @stmt = 'select productid, quantity, unitprice from '
set @stmt = @stmt + 'dbo.[order details] where orderid = '+ @orderid

EXEC (@stmt)
2010/02/22 23:12 2010/02/22 23:12
이 글에는 트랙백을 보낼 수 없습니다
저장프로시저
- 저장 프로시저는 하나 이상으로 구성된 Transact-SQL 문을 데이터베이스에 저장한 개체입니다.

저장프로시저 특징
  • 모듈 프로그래밍
    자주 반복해서 사용하는 T-SQL문을 DB에 저장해 필요한 시점에만 사용함.
    매번 같은 구문을 다시 작성할 필요가 없음
  • 유연한 보완관리
    데이터 조회하는 저장프로시저. 접근권한이 없어도 저장프로시저를 실행할 권한이 있다면 조회가능
  • 네트워크 트래픽 감소
    쿼리전체를 서버로 전송해서 작업하는 것이 아닌 저장 프로시저와 매개변수값만을 전달함으로 데이터량이 작음
  • 빠른실행
    저장프로시저는 실행후 쿼리 실행계획을 메모리에 저장 > 저장된 실행계획 사용 > 구문분석이나 최적화 과정 거치지 않아서 더 빠른 실행을 할수 있고 캐시에 없더라도 구문분석, 표준화등의 작업을 하지 않기에 성능이 빠름

저장프로저의 구성요소
저장 프로시저명, 매개변수들, SQL문, 결과값 반환의 반환값

저장프로시저의 종류
  • 확장프로시저 : C와 같은 언어를 이용해서 구현한 프로시저, master DB에만 추가가능
  • 사용자 정의 저장 프로시저 : T-SQL문을 이용해 저장 프로시저로 구현
  • 시스템 저장 프로시저 : SQL서버관리를 위해 시스템에서 제공해주는 저장 프로시저
    sys의 스키마로 나타남, 데이터베이스 명 필요없이 시스템 저장 프로시저명을 통해서 실행가능

    Sp_who, sp_who2 : 사용자 정보
    Sp_lock : lock 정보
    Sp_help : 지정한 개체 정보
    Sp_helpdb : 지정한 DB정보
    Sp_configure : SQL 서버 설정변경
  • 임시 저장프로시저
    T-SQL 문 또는 일괄처리의 실행계획을 재 사용하지 않던 이전 버전의 방식
    사용자 정의 프로시저와 동일하게 작성하지만, 저장프로시저 명을 #으로 하면 임시저장프로시저가 됨
    SQL Server 2005에서는 T-SQL문과 일괄처리의 실행계획을 재 사용할수 있음으로 임시저장프로시저 사용이 거의없음
  • CLR 저장 프로시저
    T-SQL에서 부족한 프로그래밍 부분을 CLR 저장 프로시저를 통해 T-SQL 저장 프로시저보다는 더 강력한 구조적 프로그래밍이 가능

저장 프로시저의 생성

CREATE PROCEDURE usp_withANumber <- 소문자 : 스키마. 저장 프로시저명
@ EmployeeID INT <- 매개변수, 데이터 형식
AS
SELECT ANumber, AContent, ManagerID
FROM HumanResource.analysisDate
WHERE ManagerID = @ EmployeeID
GO

EXECUTE usp_withANumber

GO
* 임시 저장프로시저의 생성은
CREATE PROCEDURE #usp_withANumber <- 소문자 : 스키마. 저장 프로시저명앞에 샾
* 저장프로시저 생성시, SP_ 접두사는 시스템저장프로시저와 혼란을 줄수 있음으로 사용금지
* 그룹화면 저장프로시저 삭제시 개별적으로 하나씩 삭제할수 없음으로 가급적 사용하지말것
- 그룹화하기 : 같은 저장 프로시저명에 ; 하고 숫자를 매김

CREATE PROCEDURE usp_withANumber;1
AS
[ T-SQL구문 ]
GO

CREATE PROCEDURE usp_withANumber;2
AS
[ T-SQL구문 ]
GO

* 다른 사용자의 접근막기위해서는 CREATE아래쪽에 WITH ENCRYPTION을 사용함
시스템뷰에서 저장프로시저의 텍스트가 나타나지 않음. 암호화된 저장프로시저의 내용은 다시 확인할수 있는 방법이 없음으로 암호화되기전의 저장프로시저를 잘 보관해야함



저장 프로시저의 수정

ALTER PROCEDURE 스키마. 저장프로시저명.
@ 매개변수 데이터 형식
AS
[ 변경된 SQL문 ]



저장 프로시저의 삭제

DROP PROCEDURE 스키마.저장프로시저명;



기본값을 지니는 매개변수의 사용과 output사용

CREATE PROCEDURE usp_withANumber
@EmployeeID INT = 10 <- EmployeeID에 기본값을 지정한 것
@outvalue int output <- outvalue에 output 변수를 쓰겠다는것
@currency_cursor CURSOR VARYING OUTPUT <- output 매개변수로 커서를 사용할때
AS
SELECT @outvalue = ManagerID <- 관리자 ID를 output 매개변수에 설정
FROM HumanResource.analysisDate
WHERE ManagerID = @ EmployeeID
GO

DECLARE @ManagerID INT; <- 저장프로시저 output 매개변수에 반환하는 값저장을 위한 지역변수선언

EXECUTE usp_withANumber 20, @ManagerID output <-반환되는값 조회

GO
2010/02/17 17:50 2010/02/17 17:50
이 글에는 트랙백을 보낼 수 없습니다

매번 까먹고 까먹는 주석 -_-
프로젝트가 끝나는 시점에 주석과의 싸움은 언제나 있는데 ..
항상 까먹는다 -_-;;


Window -> Preferences -> Java -> Code Style -> Code Templates -> Comments 에서


파일정보 주석 (소스 가장 위 상단을 선택)

Types -> Edit

/**
 * @FileName  : ${file_name}
 * @Project     : ${project_name}
 * @Date         : ${date}
 * @작성자      : ${user}

 * @변경이력 :
 * @프로그램 설명 :
 */



메소드정보 주석 (원하는 함수를 선택)

Methods -> Edit

/**
 * @Method Name  : ${enclosing_method}
 * @작성일   : ${date}
 * @작성자   : ${user}
 * @변경이력  :
 * @Method 설명 :
 * ${tags}
 */



${} 내용설명

data : Current date (현재 날짜)

dollar : The dollar symbol (달러문양)

enclosing_type :The type enclosing the method (선택된 메소드의 타입)

file_name : Name of the enclosing compilation (선택된 편집파일 이름)

package_name : Name of the enclosing package (선택된 패키지 이름)

project_name : Name of the enclosing project (선택된 프로젝트 이름)

tags : Generated Javadoc tags (@param, @return...) (Javedoc 태그 생성)

time : Current time (현재 시간)

todo : Todo task tag ('해야할일'태그 생성)

type_name : Name of the current type (현재 타입의 이름)

user : User name (사용자 이름)

year : Current year (현재 연도)



3.2 기준으로 주석입력 단축키는 ALT + SHIFT + J

2010/02/11 15:58 2010/02/11 15:58
이 글에는 트랙백을 보낼 수 없습니다

구글 논리 연산자

+ : 그 다음에 나오는 단어를 반드시 포함시킴

- : 그 다음에 나오는 단어를 검색에서 제거

| : OR연산자

() : 그룹화

 

고급 연산자

intitle : 페이지 제목에서 검색

allintitle : 연산자 뒤에 나오는 모든 단어를 페이지 제목에서 검색

inurl : url에서 검색

allinurl : 연산자 뒤의 모든 단어를 url에서 검색

site : 특정 사이트에서 검색 ex) site:tahoo.com blogs

filetype : 특정 종류의 파일 검색 ex) filetype:pdf 경제

link : 다른 페이지로의 링크를 검색

inanchor : 링크 문자열 내에서 검색

cache : 캐시로 저장된 페이지를 보여줌

2010/02/02 10:11 2010/02/02 10:11
이 글에는 트랙백을 보낼 수 없습니다
웅쓰:웅자의 상상플러스
웅자의 상상플러스
전체 (379)
게임 (5)
영화 (2)
기타 (23)
맛집 (5)
영어 (2)
대수학 (3)
형태소 (5)
Hacking (9)
Linux (112)
HTML (48)
Application_developing (48)
Web_developing (102)
Window (11)
«   2024/04   »
  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        
  1. 2016/01 (1)
  2. 2015/12 (3)
  3. 2015/10 (3)
  4. 2015/03 (2)
  5. 2015/01 (4)