ÎåÖÖÌá¸ß SQL ÐÔÄܵķ½·¨
±¾ÎĽÚÑ¡×ÔMSDNµÄÎÄÕ¡¶ÎåÖÖÌá¸ß SQL ÐÔÄܵķ½·¨¡·£¬Ìá³öÈçºÎÌá¸ß»ùÓÚSQL ServerÓ¦ÓóÌÐòµÄÔËÐÐЧÂÊ£¬·Ç³£ÖµµÃÍƼö¡£¶ÔһЩTrafficºÜ¸ßµÄÓ¦ÓÃϵͳ¶øÑÔ£¬ÈçºÎÌá¸ßºÍ¸Ä½øSQLÖ¸ÁÊǷdz£ÖØÒªµÄ£¬Ò²ÊÇÒ»¸öºÜºÃµÄÍ»ÆƵ㡣
*ÎÄÕÂÖ÷Òª°üÀ¨ÈçÏÂһЩÄÚÈÝ£¨Èç¸ÐÐËȤ£¬ÇëÖ±½Ó·ÃÎÊÏÂÃæµÄURLÔĶÁÍêÕûµÄÖÐÓ¢ÎÄÎĵµ£©£º
1, ´Ó INSERT ·µ»Ø IDENTITY
SELECT @@IDENTITY
2, ÄÚǶÊÓͼÓëÁÙʱ±í
ÁÙʱ±í £ ÔÚ tempdb ÖеÄÁÙʱ±í»áµ¼Ö²éѯ½øÐдóÁ¿ I/O ²Ù×÷ºÍ´ÅÅÌ·ÃÎÊ£¬ÁÙʱ±í»áÏûºÄ´óÁ¿×ÊÔ´¡£
ÄÚǶÊÓͼ £Ê¹ÓÃÄÚǶÊÓͼȡ´úÁÙʱ±í¡£ÄÚǶÊÓͼֻÊÇÒ»¸ö¿ÉÒÔÁª½Óµ½ from ×Ó¾äÖеIJéѯ¡£Èç¹ûÖ»ÐèÒª½«Êý¾ÝÁª½Óµ½ÆäËû²éѯ£¬Ôò¿ÉÒÔÊÔÊÔʹÓÃÄÚǶÊÓͼ£¬ÒÔ½ÚÊ¡×ÊÔ´¡£
3, ±ÜÃâ LEFT JOIN ºÍ NULL
LEFT JOIN ÏûºÄµÄ×ÊÔ´·Ç³£Ö®¶à£¬ÒòΪËüÃÇ°üº¬Óë NULL£¨²»´æÔÚ£©Êý¾ÝÆ¥ÅäµÄÊý¾Ý¡£ÔÚijЩÇé¿öÏ£¬ÕâÊDz»¿É±ÜÃâµÄ£¬µ«ÊÇ´ú¼Û¿ÉÄܷdz£¸ß¡£LEFT JOIN ±È INNER JOIN ÏûºÄ×ÊÔ´¸ü¶à£¬ËùÒÔÈç¹ûÄú¿ÉÒÔÖØбàд²éѯÒÔʹµÃ¸Ã²éѯ²»Ê¹ÓÃÈκΠLEFT JOIN£¬Ôò»áµÃµ½·Ç³£¿É¹ÛµÄ»Ø±¨¡£
¼Ó¿ìʹÓà LEFT JOIN µÄ²éѯËٶȵÄÒ»Ïî¼¼ÊõÉæ¼°´´½¨Ò»¸ö TABLE Êý¾ÝÀàÐÍ£¬²åÈëµÚÒ»¸ö±í£¨LEFT JOIN ×ó²àµÄ±í£©ÖеÄËùÓÐÐУ¬È»ºóʹÓõڶþ¸ö±íÖеÄÖµ¸üРTABLE Êý¾ÝÀàÐÍ¡£´Ë¼¼ÊõÊÇÒ»¸öÁ½²½µÄ¹ý³Ì£¬µ«Óë±ê×¼µÄ LEFT JOIN Ïà±È£¬¿ÉÒÔ½ÚÊ¡´óÁ¿Ê±¼ä¡£Ò»¸öºÜºÃµÄ¹æÔòÊdz¢ÊÔ¸÷ÖÖ²»Í¬µÄ¼¼Êõ²¢¼Ç¼ÿÖÖ¼¼ÊõËùÐèµÄʱ¼ä£¬Ö±µ½»ñµÃÓÃÓÚÄúµÄÓ¦ÓóÌÐòµÄÖ´ÐÐÐÔÄÜ×î¼ÑµÄ²éѯ¡£
DECLARE @tblMonths TABLE (sMonth VARCHAR(7))
4, Áé»îʹÓõѿ¨¶û³Ë»ý
¶ÔÓڴ˼¼ÇÉ£¬ÎÒ½«½øÐзdz£ÏêϸµÄ½éÉÜ£¬²¢ÌᳫÔÚijЩÇé¿öÏÂʹÓõѿ¨¶û³Ë»ý¡£³öÓÚijЩÔÒò£¬µÑ¿¨¶û³Ë»ý (CROSS JOIN) Ôâµ½Á˺ܶàÇ´Ô𣬿ª·¢ÈËԱͨ³£»á±»¾¯¸æ¸ù±¾¾Í²»ÒªÊ¹ÓÃËüÃÇ¡£ÔÚÐí¶àÇé¿öÏ£¬ËüÃÇÏûºÄµÄ×ÊÔ´Ì«¶à£¬´Ó¶øÎÞ·¨¸ßЧʹÓᣵ«ÊÇÏñ SQL ÖеÄÈκι¤¾ßÒ»Ñù£¬Èç¹ûÕýȷʹÓã¬ËüÃÇÒ²»áºÜÓмÛÖµ¡£
ÆäÖÐÒ»¶ÎʾÀý´úÂ룬ֵµÃЧ·Â£º
-- µÑ¿¨¶û³Ë»ýÔò¿ÉÒÔ·µ»ØËùÓÐÔ·ݵÄËùÓпͻ§¡£µÑ¿¨¶û³Ë»ý»ù±¾ÉÏÊǽ«µÚÒ»¸ö±íÓëµÚ¶þ¸ö±íÏà³Ë£¬Éú³ÉÒ»¸öÐм¯ºÏ£¬ÆäÖаüº¬µÚÒ»¸ö±íÖеÄÐÐÊýÓëµÚ¶þ¸ö±íÖеÄÐÐÊýÏà³ËµÄ½á¹û¡£Òò´Ë£¬µÑ¿¨¶û³Ë»ý»áÏò±í @tblFinal ·µ»Ø 12£¨ËùÓÐÔ·ݣ©*81£¨ËùÓпͻ§£©=972 ÐС£×îºóµÄ²½ÖèÊÇʹÓôËÈÕÆÚ·¶Î§ÄÚÿ¸ö¿Í»§µÄÔÂÏúÊÛ¶î×ܼƸüР@tblFinal ±í£¬ÒÔ¼°Ñ¡Ôñ×îÖÕµÄÐм¯¡£
DECLARE @tblMonths TABLE (sMonth VARCHAR(7))
DECLARE @tblCusto
Ïà¹ØÎĵµ£º
linq to sql ÔÚ²åÈëÖµµÄʱºò»¹ÊǺܷ½±ã¡£ÓÐʱºòÎÒÃÇÐèÒªÔÚ²åÈëÒ»¸öеÄʵÌåÖ®ºóµÃµ½ÄǸöʵÌåµÄÖ÷¼üIDµÄÖµ£¬Õâ¸öIDµ±È»±ØÐëÊÇ×ÔÔö¡£Ò»¶Îʱ¼äÎÒÒ»Ö±ÈÏΪֱ½ÓʹÓÃlinq to sqlµÄ²åÈë»úÖÆÊDz»¿ÉÒÔÔÚ×öµ½µÄ£¬ËùÒÔÖ»ÓÐʹÓô洢¹ý³ÌµÄ£¬¾ßÌå¿ÉÒԲ鿴ÕâƪÎÄÕ£ºhttp://blog.benhall.me.uk/2008/01/custom-insert-logic-with-linq-to- ......
Êý¾Ý¿â×Öµä°üÀ¨±í½á¹¹(·Ö2KºÍ2005£©¡¢Ë÷ÒýºÍÖ÷¼ü.Íâ¼ü.Ô¼Êø.ÊÓͼ.º¯Êý.´æ´¢¹ý³Ì.´¥·¢Æ÷.¹æÔò¡£¿ÉÒÔÔÚÆóÒµ¹ÜÀíÆ÷¡¢²éѯ·ÖÎöÆ÷Öмòµ¥Ö´ÐУ¬Ö±½ÓÁ˵±µÄ²é³öSQL2K¼°SQL2005µÄËùÓÐÊý¾Ý×ֵ䣬·½±ãÎĵµµÄ±àд£¬Ï£Íû¶Ô´ó¼ÒÓаïÖú¡£
1. SqlServer2000Êý¾Ý¿â×Öµä--±í½á¹¹.sql
SELECT TOP 100 PERCENT --a.id,
& ......
SQLµÄ»ù±¾¶ÔÏóÖ÷ÒªÓг£Á¿£¬±íʾ·û£¬·Ö¸ô·û£¬±£Áô¹Ø¼ü×Ö¡£
1¡¢³£Á¿
³£Á¿ÊÇÒ»¸ö°üº¬ÎÄ×ÖÓëÊý×Ö£¬Ê®Áù½øÖÆ»òÊý×Ö³£Á¿¡£Ò»¸ö×Ö·û´®³£Á¿°üº¬µ¥ÒýºÅ('')»òË«ÒýºÅ("")×Ö·û¼¯ÖеÄÒ»¸ö»ò¶à¸ö×Ö·û¡£
Èç¹ûÏëÔÚµ¥ÒýºÅ·Ö¸ôµÄ×Ö·û´®ÖÐÓõ½µ¥¶ÀµÄÒýºÅ£¬¿ÉÒÔÔÚÕâ¸ö×Ö·ûÖÐÓû§Á¬ÐøµÄµ¥ÒýºÅ£¨¼´ÓÃÁ ......
ÏÖÔÚLinq to sqlµÄ×ÊÁÏ»¹²»ÊǺܶ࣬±¾ÈËˮƽÓÐÏÞ£¬Èç¹ûÓдí»òÕßÎóµ¼ÇëÖ¸³ö£¬Ð»Ð»¡£
Ò»²½Ò»²½Ñ§Linq to sql£¨Ò»£©£ºÔ¤±¸ÖªÊ¶
Ò»²½Ò»²½Ñ§Linq to sql£¨¶þ£©£ºDataContextÓëʵÌå
Ò»²½Ò»²½Ñ§Linq to sql£¨Èý£©£ºÔöɾ¸Ä
Ò»²½Ò»²½Ñ§Linq to sql£¨ËÄ£©£º²éѯ¾ä·¨
Ò»²½Ò»²½Ñ§Linq to sql£¨Î壩£º´æ´¢¹ý³Ì
Ò»²½Ò»²½ ......
²âÊÔ»útest°²×°µÄÊÇwindows server2008+sql server 2008£¬Êý¾Ý¿â°²×°³É¹¦¡£¿ÉÒÔÁ¬½Ó¾ÖÓòÍøÄÚÆäËû»úÆ÷µÄÊý¾Ý¿â£¨ÆäËû»úÆ÷µÄÊý¾Ý¿âΪSQL 2005£©¡£µ«ÊÇÍøÄÚÆäËû»úÆ÷·ÃÎÊtestʱ£¬ÎÞ·¨Á¬½Ó£¬±¨´í¡£ÐÅϢΪ£ºÔÚ½¨Á¢Óë·þÎñÆ÷µÄÁ¬½Óʱ³ö´í¡£ÔÚÁ¬½Óµ½SQL SERVER 2005ʱ£¬ÔÚĬÈϵÄÉèÖÃÏÂSQL SERVER ²»ÔÊÐí½øÐÐÔ¶³ÌÁ¬½Ó¿ÉÄܻᵼÖ´Îʧ°Ü ......