sqlserver bcpÃüÁ¿ìËÙ´¦Àí´óÊý¾Ý
bcpÃüÁîÊÇSQL ServerÌṩµÄÒ»¸ö¿ì½ÝµÄÊý¾Ýµ¼Èëµ¼³ö¹¤¾ß¡£Ê¹ÓÃËü²»ÐèÒªÆô¶¯ÈκÎͼÐιÜÀí¹¤¾ß¾ÍÄÜÒÔ¸ßЧµÄ·½Ê½µ¼Èëµ¼³öÊý¾Ý¡£bcpÊÇSQL ServerÖиºÔðµ¼Èëµ¼³öÊý¾ÝµÄÒ»¸öÃüÁîÐй¤¾ß£¬ËüÊÇ»ùÓÚDB-LibraryµÄ£¬²¢ÇÒÄÜÒÔ²¢Ðеķ½Ê½¸ßЧµØµ¼Èëµ¼³ö´óÅúÁ¿µÄÊý¾Ý¡£bcp¿ÉÒÔ½«Êý¾Ý¿âµÄ±í»òÊÓͼֱ½Óµ¼³ö£¬Ò²ÄÜͨ¹ýSELECT fromÓï¾ä¶Ô±í»òÊÓͼ½øÐйýÂ˺󵼳ö¡£ÔÚµ¼Èëµ¼³öÊý¾Ýʱ£¬¿ÉÒÔʹÓÃĬÈÏÖµ»òÊÇʹÓÃÒ»¸ö¸ñʽÎļþ½«ÎļþÖеÄÊý¾Ýµ¼Èëµ½Êý¾Ý¿â»ò½«Êý¾Ý¿âÖеÄÊý¾Ýµ¼³öµ½ÎļþÖÐ.
1. bcpµÄÖ÷Òª²ÎÊý½éÉÜ
bcp¹²ÓÐËĸö¶¯×÷¿ÉÒÔÑ¡Ôñ¡£
(1) µ¼Èë¡£
Õâ¸ö¶¯×÷ʹÓÃinÃüÁîÍê³É£¬ºóÃæ¸úÐèÒªµ¼ÈëµÄÎļþÃû¡£
(2) µ¼³ö¡£
Õâ¸ö¶¯×÷ʹÓÃoutÃüÁîÍê³É£¬ºóÃæ¸úÐèÒªµ¼³öµÄÎļþÃû¡£
(3) ʹÓÃSQLÓï¾äµ¼³ö¡£
Õâ¸ö¶¯×÷ʹÓÃqueryoutÃüÁîÍê³É£¬Ëü¸úoutÀàËÆ£¬Ö»ÊÇÊý¾ÝÔ´²»ÊDZí»òÊÓͼÃû£¬¶øÊÇSQLÓï¾ä¡£
(4) µ¼³ö¸ñʽÎļþ¡£
Õâ¸ö¶¯×÷ʹÓÃformatÃüÁîÍê³É£¬ºó¶ø¸ú¸ñʽÎļþÃû¡£
ÏÂÃæ½éÉÜһЩ³£ÓõÄÑ¡Ï
-f format_file
format_file±íʾ¸ñʽÎļþÃû¡£Õâ¸öÑ¡ÏîÒÀÀµÓÚÉÏÊöµÄ¶¯×÷£¬Èç¹ûʹÓõÄÊÇin»òout£¬format_file±íʾÒѾ´æÔڵĸñʽÎļþ£¬Èç¹ûʹÓõÄÊÇformatÔò±íʾÊÇÒªÉú³ÉµÄ¸ñʽÎļþ¡£
-x
Õâ¸öÑ¡ÏîÒªºÍ-f format_fileÅäºÏʹÓã¬ÒÔ±ãÉú³Éxml¸ñʽµÄ¸ñʽÎļþ¡£
-F first_row
Ö¸¶¨´Ó±»µ¼³ö±íµÄÄÄÒ»Ðе¼³ö£¬»ò´Ó±»µ¼ÈëÎļþµÄÄÄÒ»Ðе¼Èë¡£
-L last_row
Ö¸¶¨±»µ¼³ö±íÒªµ¼µ½ÄÄÒ»ÐнáÊø£¬»ò´Ó±»µ¼ÈëÎļþµ¼Êý¾Ýʱ£¬µ¼µ½ÄÄÒ»ÐнáÊø¡£
-c
ʹÓÃcharÀàÐÍ×öΪ´æ´¢ÀàÐÍ£¬Ã»ÓÐǰ׺ÇÒÒÔ"\t"×öΪ×ֶηָî·û£¬ÒÔ"\n"×öΪÐзָî·û¡£
-w
ºÍ-cÀàËÆ£¬Ö»Êǵ±Ê¹ÓÃUnicode×Ö·û¼¯¿½±´Êý¾ÝʱʹÓã¬ÇÒÒÔnchar×öΪ´æ´¢ÀàÐÍ¡£
-t field_term
Ö¸¶¨×Ö·û·Ö¸î·û£¬Ä¬ÈÏÊÇ"\t"¡£
-r row_term
Ö¸¶¨Ðзָî·û£¬Ä¬ÈÏÊÇ"\n"¡£
-S server_name[ \instance_name]
Ö¸¶¨ÒªÁ¬½ÓµÄSQL Server·þÎñÆ÷µÄʵÀý£¬Èç¹ûδָ¶¨´ËÑ¡ÏbcpÁ¬½Ó±¾»úµÄSQL ServerĬÈÏʵÀý¡£Èç¹ûÒªÁ¬½Óij̨»úÆ÷ÉϵÄĬÈÏʵÀý£¬Ö»ÐèÒªÖ¸¶¨»úÆ÷Ãû¼´¿É¡£
-U login_id
Ö¸¶¨Á¬½ÓSQL SeverµÄÓû§Ãû¡£
-P password
Ö¸¶¨Á¬½ÓSQL ServerµÄÓû§ÃûÃÜÂë¡£
-T
Ö¸¶¨bcpʹÓÃÐÅÈÎÁ¬½ÓµÇ¼SQL Server¡£Èç¹ûδָ¶¨-T£¬±ØÐëÖ¸¶¨-UºÍ-P¡£
-k
Ö¸¶¨¿ÕÁÐʹÓÃnullÖµ²åÈ룬¶ø²»ÊÇÕâÁеÄĬÈÏÖµ¡£
2. ÈçºÎʹÓÃbcpµ¼³öÊý¾Ý
(1) ʹÓÃbcpµ¼³öÕû¸ö±í»òÊÓͼ¡£
bcp AdventureWorks.sales.currency out c:\currency1.txt -c -U"sa" -P"password" --ʹÓÃÃÜÂëÁ¬½Ó»òbcp AdventureWor
Ïà¹ØÎĵµ£º
Êý¾Ý¿â×Öµä°üÀ¨±í½á¹¹(·Ö2KºÍ2005£©¡¢Ë÷ÒýºÍÖ÷¼ü.Íâ¼ü.Ô¼Êø.ÊÓͼ.º¯Êý.´æ´¢¹ý³Ì.´¥·¢Æ÷.¹æÔò¡£¿ÉÒÔÔÚÆóÒµ¹ÜÀíÆ÷¡¢²éѯ·ÖÎöÆ÷Öмòµ¥Ö´ÐУ¬Ö±½ÓÁ˵±µÄ²é³öSQL2K¼°SQL2005µÄËùÓÐÊý¾Ý×ֵ䣬·½±ãÎĵµµÄ±àд£¬Ï£Íû¶Ô´ó¼ÒÓаïÖú¡£
1. SqlServer2000Êý¾Ý¿â×Öµä--±í½á¹¹.sql
SELECT TOP 100 PERCENT --a.id,
& ......
Óαê²Ù×÷µÄÁù²½Öè:
¡ôÔÚÿ´ÎÔÚ´´½¨ÓαêµÄʱºò¶¼ÎÊÎÊ×Ô¼º,ÓÃʲô±ðµÄ·½·¨¿ÉÒÔ±ÜÃâʹÓÃÓαê,ÄÇôÄã¾Í²½ÈçÉè¼ÆµÄÕý¹æÁË.
1.ÉùÃ÷
2.´ò¿ª
3.Ó¦ÓÃ/²Ù×÷
4.¹Ø±Õ.
5.ÊÍ·Å
&nbs ......
´úÂëÈçÏÂ:
DECLARE
@TempTable table(UserID int , UserName nvarchar(50));
insert into
@TempTable (UserID,UserName) values (1,'a')
insert into @TempTable
(UserID,UserName) values (2,'b')
select UserID,UserName
from @TempTable FOR XML PATH
ÔËÐÐÕâ¶Î½Å±¾£¬½«Éú³ÉÈçϽá¹û£º
¸´ÖÆ´úÂë
......
1.oracle»·¾³
create table test
(
id number(4),
name varchar2(20)
)
ÔÚÒ»¸ösessionÖÐ
insert into test values(1,'aa');
ÔÚÁíÒ»¸ösessionÖÐ
select * from test1;
²éѯû±»×èÈû
2.sqlserver»·¾³
ÔÚÒ»¸ösessionÖÐ
insert into test values(1,'aa');
ÔÚÁíÒ»¸ösessionÖÐ
select * from test1;
²éѯ±»×èÈû(Ê ......