Ìá¸ßSQLÐÔÄÜ
ÓÐʱ£¬ ΪÁËÈÃÓ¦ÓóÌÐòÔËÐеøü¿ì£¬Ëù×öµÄÈ«²¿¹¤×÷¾ÍÊÇÔÚÕâÀï»òÄÇÀï×öһЩºÜСµ÷Õû¡£°¡£¬µ«¹Ø¼üÔÚÓÚÈ·¶¨ÈçºÎ½øÐе÷Õû£¡³ÙÔçÄú»áÓöµ½ÕâÖÖÇé¿ö£ºÓ¦ÓóÌÐòÖÐµÄ SQL ²éѯ²»ÄÜ°´ÕÕÄúÏëÒªµÄ·½Ê½½øÐÐÏìÓ¦¡£ËüҪô²»·µ»ØÊý¾Ý£¬ÒªÃ´ºÄ·ÑµÄʱ¼ä³¤µÃ³öÆæ¡£Èç¹ûËü½µµÍÁ˱¨¸æ»òÄúµÄÆóÒµÓ¦ÓóÌÐòµÄËٶȣ¬Óû§±ØÐëµÈ´ýµÄʱ¼ä¹ý³¤£¬ËûÃǾͻáºÜ²»ÂúÒâ¡£¾ÍÏñÄúµÄ¸¸Ä¸²»ÏëÌýÄú½âÊÍΪʲôÔÚÉî¸ü°ëÒ¹²Å»ØÀ´Ò»Ñù£¬Óû§Ò²²»»áÌýÄã½âÊÍΪʲô²éѯºÄ·ÑÕâô³¤Ê±¼ä¡££¨“¶Ô²»Æð£¬ÂèÂ裬ÎÒʹÓÃÁËÌ«¶àµÄ LEFT JOIN¡£”£©Óû§Ï£ÍûÓ¦ÓóÌÐòÏìӦѸËÙ£¬ËûÃǵı¨¸æÄܹ»ÔÚ˲¼äÖ®ÄÚ·µ»Ø·ÖÎöÊý¾Ý¡£¾ÍÎÒ×Ô¼º¶øÑÔ£¬Èç¹ûÔÚ Web ÉϳåÀËʱij¸öÒ³ÃæÒªºÄ·ÑÊ®¶àÃë²ÅÄܼÓÔØ£¨ºÃ°É£¬ÎåÃë¸üʵ¼ÊһЩ£©£¬ÎÒÒ²»áºÜ²»ÄÍ·³¡£
ΪÁ˽â¾öÕâЩÎÊÌ⣬ÖØÒªµÄÊÇÕÒµ½ÎÊÌâµÄ¸ùÔ´¡£ÄÇô£¬´ÓÄÄÀ↑ʼÄØ£¿¸ù±¾ÔÒòͨ³£ÔÚÓÚÊý¾Ý¿âÉè¼ÆºÍ·ÃÎÊËüµÄ²éѯ¡£ÔÚ±¾ÔµÄרÀ¸ÖУ¬ÎÒ½«½²ÊöËÄÏî¼¼Êõ£¬ÕâЩ¼¼Êõ¿ÉÓÃÓÚÌá¸ß»ùÓÚ SQL Server? µÄÓ¦ÓóÌÐòµÄÐÔÄÜ»ò¸ÄÉÆÆä¿ÉÉìËõÐÔ¡£ÎÒ½«×Ðϸ˵Ã÷ LEFT JOIN¡¢CROSS JOIN µÄʹÓÃÒÔ¼° IDENTITY ÖµµÄ¼ìË÷¡£Çë¼Çס£¬¸ù±¾Ã»ÓÐÉñÆæµÄ½â¾ö·½°¸¡£µ÷ÕûÄúµÄÊý¾Ý¿â¼°Æä²éѯÐèÒªÕ¼ÓÃʱ¼ä¡¢½øÐзÖÎö£¬»¹ÐèÒª´óÁ¿µÄ²âÊÔ¡£ÕâЩ¼¼Êõ¶¼Òѱ»Ö¤Ã÷ÐÐÖ®ÓÐЧ£¬µ«¶ÔÄúµÄÓ¦ÓóÌÐò¶øÑÔ£¬¿ÉÄÜÆäÖÐһЩ¼¼Êõ±ÈÁíһЩ¼¼Êõ¸üÊÊÓá£
´Ó INSERT ·µ»Ø IDENTITY
ÎÒ¾ö¶¨´ÓÓöµ½Ðí¶àÎÊÌâµÄÄÚÈÝÈëÊÖ£ºÈçºÎÔÚÖ´ÐÐ SQL INSERT ºó¼ìË÷ IDENTITY Öµ¡£Í¨³££¬ÎÊÌâ²»ÔÚÓÚÈçºÎ±àд¼ìË÷ÖµµÄ²éѯ£¬¶øÔÚÓÚÔÚÄÄÀïÒÔ¼°ºÎʱ½øÐмìË÷¡£ÔÚ SQL Server ÖУ¬ÏÂÃæµÄÓï¾ä¿ÉÓÃÓÚ¼ìË÷ÓÉ×îÐÂÔڻÊý¾Ý¿âÁ¬½ÓÉÏÔËÐÐµÄ SQL Óï¾äËù´´½¨µÄ IDENTITY Öµ£º
SELECT @@IDENTITYÕâ¸ö SQL Óï¾ä²¢²»¸´ÔÓ£¬µ«ÐèÒª¼ÇסµÄÒ»µãÊÇ£ºÈç¹ûÕâ¸ö×îÐ嵀 SQL Óï¾ä²»ÊÇ INSERT£¬»òÕßÄúÕë¶Ô·Ç INSERT SQL µÄÆäËûÁ¬½ÓÔËÐÐÁË´Ë SQL£¬Ôò²»»á»ñµÃÆÚÍûµÄÖµ¡£Äú±ØÐëÔËÐÐÏÂÁдúÂë²ÅÄܼìË÷½ô¸úÔÚ INSERT SQL Ö®ºóÇÒλÓÚͬһÁ¬½ÓÉ쵀 IDENTITY£¬ÈçÏÂËùʾ£º
INSERT INTO Products (ProductName) VALUES ('Chalk')
SELECT @@IDENTITYÔÚÒ»¸öÁ¬½ÓÉÏÕë¶Ô Northwind Êý¾Ý¿âÔËÐÐÕâЩ²éѯ½«·µ»ØÒ»¸öÃû³ÆΪ Chalk µÄвúÆ·µÄ IDENTITY Öµ¡£ËùÒÔ£¬ÔÚʹÓà ADO µÄ Visual Basic? Ó¦ÓóÌÐòÖУ¬¿ÉÒÔÔËÐÐÒÔÏÂÓï¾ä£º
Set oRs = oCn.Execute("SET NOCOUNT ON;INSERT INTO Products _
(ProductName) VALUES ('Chalk');SELECT @@IDENTITY")
lProductID = oRs(0)´Ë´úÂë¸æËß SQL Serve
Ïà¹ØÎĵµ£º
Óï¾ä£ºselect rank() over(Order By ±íµÄÖ÷¼ü Desc) As UID ,ÆäËûÁÐ from ±í
˵Ã÷£ºrankº¯Êý
×÷Óãº
·µ»ØÖ¸¶¨Ôª×éÔÚÖ¸¶¨¼¯ÖеÄÅÅÃû£¨ÅÅÃû´Ó 1 ¿ªÊ¼£©
Rank(Tuple_Expression, Set_Expression [ ,Numeric Expression ] )
²ÎÊý£º
Tuple_Expression
Ò»¸öÓÐЧµÄ¶àά±í´ïʽ (MDX) Ôª ......
ͨ³££¬ÄãÐèÒª»ñµÃµ±Ç°ÈÕÆںͼÆËãһЩÆäËûµÄÈÕÆÚ£¬ÀýÈ磬ÄãµÄ³ÌÐò¿ÉÄÜÐèÒªÅжÏÒ»¸öÔµĵÚÒ»Ìì»òÕß×îºóÒ»Ìì¡£ÄãÃǴ󲿷ÖÈË´ó¸Å¶¼ÖªµÀÔõÑù°ÑÈÕÆÚ½øÐзָÄê¡¢Ô¡¢Èյȣ©£¬È»ºó½ö½öÓ÷ָî³öÀ´µÄÄê¡¢Ô¡¢ÈյȷÅÔÚ¼¸¸öº¯ÊýÖмÆËã³ö×Ô¼ºËùÐèÒªµÄÈÕÆÚ£¡ÔÚÕâƪÎÄÕÂÀÎÒ½«¸æËßÄãÈçºÎʹÓÃDATEADDºÍDATEDIFFº¯ÊýÀ´¼ÆËã³öÔÚÄãµÄ³ÌÐòÖ ......
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE data ......
ÎÒÃÇÒª×öµ½²»µ«»áдSQL,»¹Òª×öµ½Ð´³öÐÔÄÜÓÅÁ¼µÄSQL,ÒÔÏÂΪ±ÊÕßѧϰ¡¢ÕªÂ¼¡¢²¢»ã×ܲ¿·Ö×ÊÁÏÓë´ó¼Ò·ÖÏí£¡
£¨1£© Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLE µÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom× ......
SQL code
ÈÎÎñµ÷¶È
ÆóÒµ¹ÜÀíÆ÷
--¹ÜÀí
--SQL Server´úÀí
--ÓÒ¼ü×÷Òµ
--н¨×÷Òµ
--"³£¹æ"ÏîÖÐÊäÈë×÷ÒµÃû³Æ
--"²½Öè"Ïî
--н¨
--"²½ÖèÃû"ÖÐÊäÈë²½ÖèÃû
--"ÀàÐÍ"ÖÐÑ¡Ôñ"Transact-SQL ½Å±¾(TSQL)"
--"Êý¾Ý¿â"Ñ¡ÔñÖ´ÐÐÃüÁîµÄÊý¾Ý¿â
--"ÃüÁî"ÖÐÊäÈëÒªÖ´ÐеÄÓï¾ä:
insert b.dbo.tablename ......