sql server µÄ bcp µ¼Èëµ¼³ö
Ò»£¬
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µ¼³öÕû¸ö±í»òÊÓͼ
Ïà¹ØÎĵµ£º
ÉϽÚÎÒÃǽéÉÜÁ˱íÁ¬½Ó£¬¸üÈ·ÇеÄ˵ÊÇinner joins內Á¬½Ó£®
¡¡¡¡內Á¬½Ó½öÑ¡³öÁ½ÕűíÖл¥ÏàÆ¥ÅäµÄ¼Ç¼£®Òò´Ë£¬Õâ»áµ¼ÖÂÓÐʱÎÒÃÇÐèÒªµÄ¼Ç¼ûÓаüº¬½øÀ´¡£
¡¡¡¡Îª¸üºÃµÄÀí½âÕâ¸ö¸ÅÄÎÒÃǽéÉÜÁ½¸ö±í×÷ÑÝʾ¡£ËÕ¸ñÀ¼Òé»áÖеÄÕþµ³±í(party)ºÍÒéÔ±±í(msp)¡£
party(Code,Name,Leader)
Code: Õþµ³´úÂë
Name: Õþµ³ ......
ORACLE PL/SQLÓëSQL SERVER T-SQLһЩ±È½Ï
×Ö·û´®Á¬½Ó
OracleÓÃ|| ·ûºÅ×÷ΪÁ¬½Ó·û£¬¶øSQL ServerµÄÁ¬½Ó·ûÊǼӺţº+ ¡£
Oracle²éѯÈçÏÂËùʾ£ºSelect ‘Name’ || ‘Last Name’ from tableName
SQL Server²éѯÈçÏ£ºSelect ‘Name’ + ‘Last Name’
GUID
OracleÓÃSYS_GUID ......
SELECT ID,TITLE,
(SELECT TIMES from CLS_COURSE WHERE CLS_COURSE.ID=CLS_CLASS.COURSEID) AS TIMES,
(SELECT CASE WHEN EXISTS(SELECT * from CLS_ATDC WHERE CLS_ATDC.CLSID=CLS_CLASS.ID ) THEN (SELECT TOP 1 COURSETIME from CLS_ATDC WHERE CLS_ATDC.CLSID=CLS_CLASS.ID ORDER BY COURSETIME DESC) ELSE 0 ......
ORACLE³£ÓÃSQLÓÅ»¯hintÓï¾ä
http://oracle.chinaitlab.com/induction/802186.html
ÔÚSQLÓï¾äÓÅ»¯¹ý³ÌÖУ¬ÎÒÃǾ³£»áÓõ½hint,ÏÖ×ܽáÒ»ÏÂÔÚSQLÓÅ»¯¹ý³ÌÖг£¼ûOracle HINTµÄÓ÷¨£º
¡¡¡¡1. /*+ALL_ROWS*/
¡¡¡¡±íÃ÷¶ÔÓï¾ä¿éÑ¡Ôñ»ùÓÚ¿ªÏúµÄÓÅ»¯·½·¨,²¢»ñµÃ×î¼ÑÍÌÍÂÁ¿,ʹ×ÊÔ´ÏûºÄ×îС»¯.
¡¡¡¡ÀýÈç:
¡¡¡¡SELECT /*+ALL+_ROW ......
¹ØÓÚSQL Prompt
µÄÆƽâÎÄÕÂÔ°×ÓÀïÒѾÓв»ÉÙÈË·¢¹ýÁË¡£Æƽâ˼·ÎÒÒ²²»ÏëÖظ´£¬²»ÖªµÀµÄ¿ÉÒԲο¼£ºhttp://www.cnblogs.com/jintan/archive/2008/06/16/1223282.html
¹Ù·½ÏÂÔصØÖ·ÊÇ£ºhttp://downloads.red-gate.com/SQLToolbelt.exe
½ÓÏÂÀ´ÎÒ¾Í˵˵¾ßÌåÔõô×ö°É¡£ÎÒ¾Í˵˵×î¼òµ¥×îɵ¹ÏµÄ×ö·¨£¬²»ÐèÒª¶®ILÕÕÑùÆƽ⣡
× ......