Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL ÖÐWith as µÄÓ÷¨

Ò»£®WITH ASµÄº¬Òå
WITH AS¶ÌÓҲ½Ð×ö×Ó²éѯ²¿·Ö£¨subquery factoring£©£¬¿ÉÒÔÈÃÄã×öºÜ¶àÊÂÇ飬¶¨ÒåÒ»¸öSQLƬ¶Ï£¬¸ÃSQLƬ¶Ï»á±»Õû¸öSQLÓï¾äËùÓõ½¡£ÓеÄʱºò£¬ÊÇΪÁËÈÃSQLÓï¾äµÄ¿É¶ÁÐÔ¸ü¸ßЩ£¬Ò²ÓпÉÄÜÊÇÔÚUNION ALLµÄ²»Í¬²¿·Ö£¬×÷ΪÌṩÊý¾ÝµÄ²¿·Ö¡£
Ìرð¶ÔÓÚUNION ALL±È½ÏÓÐÓá£ÒòΪUNION ALLµÄÿ¸ö²¿·Ö¿ÉÄÜÏàͬ£¬µ«ÊÇÈç¹ûÿ¸ö²¿·Ö¶¼È¥Ö´ÐÐÒ»±éµÄ»°£¬Ôò³É±¾Ì«¸ß£¬ËùÒÔ¿ÉÒÔʹÓÃWITH AS¶ÌÓÔòÖ»ÒªÖ´ÐÐÒ»±é¼´¿É¡£Èç¹ûWITH AS¶ÌÓïËù¶¨ÒåµÄ±íÃû±»µ÷ÓÃÁ½´ÎÒÔÉÏ£¬ÔòÓÅ»¯Æ÷»á×Ô¶¯½«WITH AS¶ÌÓïËù»ñÈ¡µÄÊý¾Ý·ÅÈëÒ»¸öTEMP±íÀÈç¹ûÖ»ÊDZ»µ÷ÓÃÒ»´Î£¬Ôò²»»á¡£¶øÌáʾmaterializeÔòÊÇÇ¿Öƽ«WITH AS¶ÌÓïÀïµÄÊý¾Ý·ÅÈëÒ»¸öÈ«¾ÖÁÙʱ±íÀï¡£ºÜ¶à²éѯͨ¹ýÕâÖÖ·½·¨¶¼¿ÉÒÔÌá¸ßËٶȡ£
¶þ£®Ê¹Ó÷½·¨
ÏÈ¿´ÏÂÃæÒ»¸öǶÌ׵IJéѯÓï¾ä£º
select * from person.StateProvince where CountryRegionCode in
(select CountryRegionCode from person.CountryRegion where Name like 'C%')
ÉÏÃæµÄ²éѯÓï¾äʹÓÃÁËÒ»¸ö×Ó²éѯ¡£ËäÈ»ÕâÌõSQLÓï¾ä²¢²»¸´ÔÓ£¬µ«Èç¹ûǶÌ׵IJã´Î¹ý¶à£¬»áʹSQLÓï¾ä·Ç³£ÄÑÒÔÔĶÁºÍά»¤¡£Òò´Ë£¬Ò²¿ÉÒÔʹÓñí±äÁ¿µÄ·½Ê½À´½â¾öÕâ¸öÎÊÌ⣬SQLÓï¾äÈçÏ£º
declare @t table(CountryRegionCode nvarchar(3))
insert into @t(CountryRegionCode) (select CountryRegionCode from person.CountryRegion where Name like 'C%')
select * from person.StateProvince where CountryRegionCode
in (select * from @t)
ËäÈ»ÉÏÃæµÄSQLÓï¾äÒª±ÈµÚÒ»ÖÖ·½Ê½¸ü¸´ÔÓ£¬µ«È´½«×Ó²éѯ·ÅÔÚÁ˱í±äÁ¿@tÖУ¬ÕâÑù×ö½«Ê¹SQLÓï¾ä¸üÈÝÒ×ά»¤£¬µ«ÓÖ»á´øÀ´ÁíÒ»¸öÎÊÌ⣬¾ÍÊÇÐÔÄܵÄËðʧ¡£ÓÉÓÚ±í±äÁ¿Êµ¼ÊÉÏʹÓÃÁËÁÙʱ±í£¬´Ó¶øÔö¼ÓÁ˶îÍâµÄI/O¿ªÏú£¬Òò´Ë£¬±í±äÁ¿µÄ·½Ê½²¢²»Ì«ÊʺÏÊý¾ÝÁ¿´óÇÒƵ·±²éѯµÄÇé¿ö¡£Îª´Ë£¬ÔÚSQL Server 2005ÖÐÌṩÁËÁíÍâÒ»ÖÖ½â¾ö·½°¸£¬Õâ¾ÍÊǹ«Óñí±í´ïʽ£¨CTE£©£¬Ê¹ÓÃCTE£¬¿ÉÒÔʹSQLÓï¾äµÄ¿Éά»¤ÐÔ£¬Í¬Ê±£¬CTEÒª±È±í±äÁ¿µÄЧÂʸߵöࡣ
ÏÂÃæÊÇCTEµÄÓï·¨£º
[ WITH <common_table_expression> [ ,n ] ]
<common_table_expression>::=
expression_name [ ( column_name [ ,n ] ) ]
AS
( CTE_query_definition )
ÏÖÔÚʹÓÃCTEÀ´½â¾öÉÏÃæµÄÎÊÌ⣬SQLÓï¾äÈçÏ£º
with
cr as
(
select CountryRegionCode from person.CountryRegion where Name like 'C%'
)
select * from person.StateProvince where CountryRegionCode in (select * from c


Ïà¹ØÎĵµ£º

SQL Server 2008¼¸ÏîÐÂÌØÐÔ¸ÅÊö

¼Æ»®ÓÚ2008ÄêµÚÒ»¼¾¶È·¢²¼µÄSQL Server 2008²»½ö¶ÔÔ­ÓÐÐÔÄܽøÐÐÁ˸Ľø£¬»¹Ìí¼ÓÁËÐí¶àÐÂÌØÐÔ£¬±ÈÈçÐÂÌíÁËÊý¾Ý¼¯³É¹¦ÄÜ£¬¸Ä½øÁË·ÖÎö·þÎñ£¬±¨¸æ·þÎñ£¬ÒÔ¼°Office¼¯³ÉµÈµÈ¡£
¡¡¡¡SQL Server¼¯³É·þÎñ
¡¡¡¡SSIS(SQL Server¼¯³É·þÎñ)ÊÇÒ»¸öǶÈëʽӦÓóÌÐò£¬ÓÃÓÚ¿ª·¢ºÍÖ´ÐÐETL(½âѹËõ¡¢×ª»»ºÍ¼ÓÔØ)°ü¡£SSIS´úÌæÁËSQL 2000µÄDTS¡£Õ ......

SQL Server2008ÐÐÊý¾ÝºÍÒ³Êý¾ÝѹËõ½âÃÜ

SQL Server2008ÐÐÊý¾ÝºÍÒ³Êý¾ÝѹËõ½âÃÜ
 
Êý¾ÝѹËõÒâζ׿õСÊý¾ÝµÄÓдÅÅÌÕ¼ÓÃÁ¿£¬ËùÒÔÊý¾ÝѹËõ¿ÉÒÔÓÃÔÚ±í£¬¾Û¼¯Ë÷Òý£¬·Ç¾Û¼¯Ë÷Òý£¬ÊÓͼË÷Òý»òÊÇ·ÖÇø±í£¬·ÖÇøË÷ÒýÉÏ¡£2.Ç°±êѹËõ£ºÃ¿Ò»Ò³ÖеÄËùÓÐÁУ¬ÔÚÐбêÍ·ÏÂÃ棬ÿÐж¼´æ´¢×ÅÒ»¸öÐж¨ÒåÖµ£¬Ñ¹Ëõºó£¬ËùÓÐÐеĶ¨ÒåÖµ¶¼±»Ìæ»»³ÉÐÐÍ·ÖµµÄÒýÓá£
¡¡¡¡±¾ÎĽ«Îª´ó¼Ò½éÉÜ ......

SQLÖÐCONVERTת»¯º¯ÊýµÄÓ÷¨

¸ñʽ:
CONVERT(data_type,expression[,style])
˵Ã÷:
´ËÑùʽһ°ãÔÚʱ¼äÀàÐÍ(datetime,smalldatetime)Óë×Ö·û´®ÀàÐÍ(nchar,nvarchar,char,varchar)
Ï໥ת»»µÄʱºò²ÅÓõ½.
Àý×Ó:
SELECT CONVERT(varchar(30),getdate(),101) now
½á¹ûΪ:
now
---------------------------------------
|09/15/2001
=============== ......

asp.netÁ¬½ÓSQL ºÍACCESSÊý¾Ý¿â

ASP.NETÈçºÎÁ¬½ÓAccess»òSQL ServerÊý¾Ý¿â 
Ê×ÏÈ¿´Ò»¸öÀý×Ó´úÂëƬ¶Ï:
³ÌÐò´úÂë: 
--------------------------------------------------------------------------------
using System.Data;
using System.Data.OleDb;
......
string strConnection="Provider=Microsoft.Jet.OleDb.4.0;";
strConnection+ ......

Microsoft SQL Azure ³£¼ûÎÊÌâ½â´ð

¹«¸æ£º±¾²©¿ÍΪ΢ÈíÔƼÆËãÖÐÎIJ©¿ÍµÄ¾µÏñ²©¿Í£¬²¢²»±£Ö¤Á´½Ó¿ÉÓÃÐÔ£¬ÎªÁ˱£Ö¤ÔĶÁÌåÑ飬Çë·ÃÎÊhttp://blogs.msdn.com/azchina¡£
 
 
October CTPµÄ SQL Azure DatabaseµÄ¹Ø¼ü¹«¸æÊÇʲô£¿
    October CTPµÄSQL Azure database¶ÔÓÚPDC2009À´Ëµ»ù±¾¹¦ÄÜÒѾ­Íê³ÉÁË¡£ October CTP&nbs ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ