반응형

bcp migration~~~


bcp util은 sybase 혹은 mssql에 내장되어 있는 UTIL입니다.

사용법은 다음과 같습니다.

왝~ 뭐가 이렇게 많아..

그러나 다 사용되는 놈들이랍니다.

간단히 정말 간단히 bcp 로 백업해봅시다.


bcp [[database_name.]owner.]table_name[:slice_number] {in | out} datafile


[-m maxerrors] [-f formatfile] [-e errfile]

[-F firstrow] [-L lastrow] [-b batchsize]

[-n] [-c] [-t field_terminator] [-r row_terminator]

[-U username] [-P password] [-I interfaces_file] [-S server]

[-a display_charset] [-q datafile_charset] [-z language] [-v]

[-A packet size] [-J client character set]

[-T text or image size] [-E] [-g id_start_value] [-N] [-X]

[-M LabelName LabelValue] [-labeled]

[-K keytab_file] [-R remote_server_principal]

[-V [security_options]] [-Z security_mechanism] [-Q]


예로

bcp pubs2..authors out "c:\ddd.dat" -c -Usa -P

치시면 pubs2라는 db에 authors가 ddd.dat라는 파일로 c:\에 생성됩니다.

그러면 집어넣을때는

bcp pubs2..authors in "c:\ddd.dat" -c -Usa -P

화 ~~~ 정말 간단하죠.. 그럼 아주 유용한 팁을 하나 소개하겠습니다.

dos창을 띄워서 혹은 UNIX 유저는 terminal을 하나 띄워서 다음과 같은 bcptest.sql이라는 화일을 만듭니다. 내용은 다음과 같이 적어 주세요


use pubs2

go

select 'bcp pubs2..'+name+' out '+name+'.dat -c -Usa -P' from sysobjects where type='U'

go


당연히 -P 다음에는 sa의 password를 적어야 합니다.

글구 저는 pubs2 라는 테스트 db의 테이블들을 bcp로 카피한겁니다.

그러니까 여러분은 bcp로 카피하고자 하는 테이블이 있는 데이타베이스를 적어 주세요.

화일을 저장하고 파일이 있는 디렉토리에서 다음을 실행시킵니다.

(주의:이때 위에서 c:\에서 했다고 c:\에서 실행하지 마세요.

c:\에 bcp라는 폴더를 맹글구 난다음 그 안에 bcptest.sql를 맹글구 test하십쇼)


isql -Usa -P -ibcptest.sql -oresult.sql


그럼 result.sql이 현재의 디렉토리에 생성됩니다. 내용을 보세요.


------------------------------------------------------------------------------bcp pubs2..authors out authors.dat -c -Usa -P


bcp pubs2..publishers out publishers.dat -c -Usa -P


bcp pubs2..roysched out roysched.dat -c -Usa -P


bcp pubs2..sales out sales.dat -c -Usa -P


bcp pubs2..salesdetail out salesdetail.dat -c -Usa -P


bcp pubs2..titleauthor out titleauthor.dat -c -Usa -P


bcp pubs2..titles out titles.dat -c -Usa -P


bcp pubs2..stores out stores.dat -c -Usa -P


bcp pubs2..discounts out discounts.dat -c -Usa -P


bcp pubs2..au_pix out au_pix.dat -c -Usa -P


bcp pubs2..blurbs out blurbs.dat -c -Usa -P


(11 rows affected)


다음과 같죠... 흠 이것에서 맨위에 -------

을 없애고 맨밑에 (11 rows affected)을 없애고 저장하면 ....

흐 NT에서는 이 파일을 생성할때 result.sql 말구 result.bat로 생성하세요.

글구 발로 클릭하면 현재의 디렉토리에 bcp 된 화일이 자~~르륵

UNIX에서는 chmod로 실행 퍼미션을 주시고...실행하시면 자르륵 어서 해보세요.

담은 집어넣는거 할겁니다.




출처 : http://ase.sni.co.kr/

+ Recent posts