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

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


Ïà¹ØÎĵµ£º

¡¾»ã×Ü¡¿SQL CODE ¾­µä·¾«²Ê

¡¾»ã×Ü¡¿SQL CODE --- ¾­µä·¾«²Ê
Êý¾Ý²Ù×÷Àà SQLHelper.cs
ÎÞÏÞ¼¶·ÖÀà ´æ´¢¹ý³Ì
°ÙÍò¼¶·ÖÒ³´æ´¢
SQL¾­µä¶ÌС´úÂëÊÕ¼¯
 
ѧÉú±í ¿Î³Ì±í ³É¼¨±í ½Ìʦ±í
50¸ö³£ÓÃsqlÓï¾ä
SQL SERVER
ÓëACCESS¡¢EXCELµÄÊý¾Ýת»»
 
Óαê
¸ù¾Ý²»Í¬µÄÌõ¼þ²éѯ²»Í¬µÄ±í
INNER JOIN Óï·¨
master.dbo.sp ......

SQL Server 2005/2008 °²È«¼à¿Ø£¨´ýÐø£©

-- ²é¿´µ±Ç°dbµÄµÇ½
select * from sys.sql_logins
-- ÉóºËµÇ½Êý¾Ý¿âµÄÓû§
sql server managerment studioÖУ¬ÓÒ¼üµã¿ª·þÎñÆ÷µÄÊôÐÔ£¬ÔÚ°²È«ÐÔҳǩÖУ¬ Ñ¡ÖÐÉóºË“³É¹¦ºÍʧ°ÜµÄµÇ½”£¬ËùÓеǽ¶¼»áÔÚ..MSSQL\Log\ERRORLOGÖмǼһÌõ¼Ç¼¡£
Èç¹û¹´Ñ¡“ÆôÓÃC2ÉóºË¸ú×Ù”£¬½«»áÔÚ..MSSQL\Log\Ŀ¼ ......

sqlÓï¾äÓÅ»¯

SQLÓï¾äµÄÓÅ»¯¾ÍÊǽ«ÐÔÄܽϵ͵ÄSQLÓï¾äת»»´ï³ÉͬÑùÄ¿µÄÐÔÄÜÓÅÒìµÄSQLÓï¾ä
ÏÂÃæÎÒÃÇÒ»ÆðÀ´¿´¿´Ò»Ð©¿ÉÒÔÓÅ»¯SQLµÄ·½·¨£¬Ï£Íû´ó¼Ò¶àÌá³öÒâ¼ûÎÒÃǹ²Í¬Ñ§Ï°»òÕßÊÇ´ó¼ÒÓÐʲôºÃµÄÓÅ»¯·½·¨¿ÉÒÔÌá³öÀ´¹²Ïíһϡ£
µÚÒ»ÖÖÓÅ»¯£¨Ê¹ÓÃÖ¸¶¨ÁдúÌæ”*”£©
       ʹÓÓ*”¿ÉÒÔ½µµÍ±àдSQLÓï ......

³£ÓÃSQLÓï¾äÊÕ¼¯

1.ɾ³ý±í
  select 'drop table ' || table_name || ' purge;'
  from user_tables
  where length(table_name) <= 4;
    ɾ³ý´øÔ¼ÊøµÄ±í
    Drop table ±íÃû cascade  constraints;
2.²éѯview&ͬÒå´Ê
   --˵Ã÷£º¿ÉÒÔ¸ù¾ÝÊÓͼµÄtext_length ......

SQL Server 2008±íÉè¼ÆÆ÷ÖÐÎÞ·¨±£´æÐÞ¸Ä

µ±Ê¹ÓÃMicrosoft SQL Server 2008 Management Studioʱ£¬ÓÐʱÔÚ±íÉè¼ÆÆ÷ÖжԱíËù×öµÄ¸ü¸ÄÎÞ·¨±£´æ£¬¾ßÌå±íÏÖΪ£ºµã»÷±£´æ°´Å¥ºóµ¯³ö±£´æ¶Ô»°¿òÌáʾ£º²»ÔÊÐí±£´æÐÞ¸Ä(Saving changes is not permitted)£¬µ¯³öµÄ¶Ô»°¿òÖ»ÓÐ2¸ö°´Å¥¿ÉÒÔµã»÷£¬Ò»¸öCancelÒ»¸öSave Text File£¬Ç°Ò»¸ö¾Í²»ÓÃ˵ÁË£¬ºóÒ»¸ö±£´æµÄÎļþ¸ù±¾Ã»ÒâÒ壨¿ÉÒ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ