Flat hierarchyid in SQL Server 2008
ÔÚSQL Server 2008ÖÐÒýÈëÁËhierarchyidÀ´´¦ÀíÊ÷×´½á¹¹¡£ÏÂÃæ¼òµ¥¾ÍÒÔAdventureWorks(ÎÞhierarchyid)ºÍAdventureWorks2008(ÓÐhierarchyid)ÀïµÄHumanResources.EmployeeΪÀý£¬À´ËµÃ÷Ò»ÏÂÔÚеÄhierarchyidÖÐÈçºÎ½øÐÐflat»¯µÄdimension³éÈ¡¡£
AdventureWorksÊÇ΢ÈíΪSQL ServerÌṩµÄÊý¾Ý¿âÐéÄâ°¸Àý¡£
AdventureWorksÖÐËùÒªµÄ½á¹û¼¯´úÂëÈçÏÂ:
select L4.NationalIDNumber, L4.Title, L3.NationalIDNumber, L3.Title, L2.NationalIDNumber, L2.Title, L1.NationalIDNumber, L1.Title, L0.NationalIDNumber, L0.Title
from HumanResources.Employee L4, HumanResources.Employee L3, HumanResources.Employee L2, HumanResources.Employee L1, HumanResources.Employee L0
where L4.ManagerID = L3.EmployeeID and L3.ManagerID = L2.EmployeeID and L2.ManagerID = L1.EmployeeID and L1.ManagerID = L0.EmployeeID
AdventureWorks2008ÖеĴúÂëÈçÏÂ:
select L4.NationalIDNumber, L4.JobTitle, L3.NationalIDNumber, L3.JobTitle, L2.NationalIDNumber, L2.JobTitle, L1.NationalIDNumber, L1.JobTitle, L0.NationalIDNumber, L0.JobTitle
from HumanResources.Employee L0, HumanResources.Employee L1, HumanResources.Employee L2, HumanResources.Employee L3, HumanResources.Employee L4
where L4.OrganizationNode.GetAncestor(1)=L3.OrganizationNode and L3.OrganizationNode.GetAncestor(1)=L2.OrganizationNode and L2.OrganizationNode.GetAncestor(1)=L1.OrganizationNode and L1.OrganizationNode.GetAncestor(1)=L0.OrganizationNode
GetAncestor()ÊÇHierarchyNodeÀàÀïÆäÖеÄÒ»¸ö·½·¨¡£¸ü¶àhierarchyidÊý¾ÝÀàÐÍ·½·¨ÒýÓÿɲο¼ÒÔÏÂÁ´½Ó£º
http://technet.microsoft.com/zh-cn/library/bb677193.aspx
Ïà¹ØÎĵµ£º
[MySQLÓÅ»¯] -- ÈçºÎÁ˽âSQLµÄÖ´ÐÐÆµÂÊ
ʱ¼ä:2010-2-28À´Ô´:HaCMS¿ªÔ´ÉçÇø ×÷Õß:chuxu
MySQL ¿Í»§¶ËÁ¬½Ó³É¹¦ºó£¬Í¨¹ý show [session|global]status ÃüÁî ¿ÉÒÔÌṩ·þÎñÆ÷״̬ÐÅÏ¢£¬Ò²¿ÉÒÔÔÚ²Ù×÷ϵͳÉÏʹÓà mysqladmin extended-status ÃüÁî»ñµÃÕâЩÏûÏ¢¡£ show [session|global] status ¿ÉÒÔ¸ù¾ÝÐèÒª¼ÓÉϲÎÊý&ldquo ......
½ñÌìÏÂÁ˸öWIN7µÄÓ¢Îİü°Ñϵͳ»»³ÉÓ¢Îĵġ£¸Ð¾õ»¹ÐУ¬¿ÉÊǵ±´´½¨Êý¾Ý¿â±íʱ·¢ÏÖ³ö´íÁË£¬²éÁËϲÅÖªµÀÊÇSQLµÄÅÅÐò³öÎÊÌâÁË
ÏÂÃæÊÇCTRL+c V¸ã¹ýÀ´µÄ£¬Ö»ÊÇ·½±ã´ó¼ÒÓÐÕâÑùµÄÎÊÌâ¿ÉÒԵõ½½â¾ö
ʹÓÃSQL2005½øÐд´½¨Êý¾Ý¿âµÄʱºò£¬Èç¹ûÓöµ½´´½¨Ê§°ÜµÄÇé¿ö£¬ÈçÏ£º
Create ¶ÔÓÚ Êý¾Ý¿â“xxxx”ʧ°Ü¡£ (Microsoft.SqlS ......
SQL Select IntoÓï¾ä
The SELECT INTO Statement
SELECT INTO Óï¾ä
The SELECT INTO statement is most often used to create backup copies of tables or for archiving records.
SELECT INTOÓï¾ä³£ÓÃÀ´¸øÊý¾Ý±í½¨Á¢±¸·Ý»òÊÇÀúÊ·µµ°¸¡£
Syntax
Óï·¨
SELECT column_name(s) INTO newtable [IN externaldatabase] ......
1.Çó1..10żÊýÖ®ºÍ
select sum(level) from dual
where mod(level,2)=0
connect by level
2.½«update¸Ä»»³ÉÓÃrowidÀ´ÊµÏÖ¡£
£¨1£©ÐµÄд·¨£º
merge into SNAPSHOT120_2010_572 t1
using (select a.rowid rid, b.vip_level, b.manager_name
from xyf_vip_info_new b, snapsho ......
µ±Ê¹ÓÃMicrosoft SQL Server 2008 Management Studioʱ£¬ÓÐʱÔÚ±íÉè¼ÆÆ÷ÖжԱíËù×öµÄ¸ü¸ÄÎÞ·¨±£´æ£¬¾ßÌå±íÏÖΪ£ºµã»÷±£´æ°´Å¥ºóµ¯³ö±£´æ¶Ô»°¿òÌáʾ£º²»ÔÊÐí±£´æÐÞ¸Ä(Saving changes is not permitted)£¬µ¯³öµÄ¶Ô»°¿òÖ»ÓÐ2¸ö°´Å¥¿ÉÒÔµã»÷£¬Ò»¸öCancelÒ»¸öSave Text File£¬Ç°Ò»¸ö¾Í²»ÓÃ˵ÁË£¬ºóÒ»¸ö±£´æµÄÎļþ¸ù±¾Ã»ÒâÒ壨¿ÉÒ ......