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

´«ÖDz¥¿Í£­Tree in SQL£¨ÒëÎÄ£©£¨3£©

This has some predictable results that we can use for building queries. The root is always of the form (left = 1, right = 2 * (SELECT COUNT(*) from TreeTable)); leaf nodes always have (left + 1 = right); the BETWEEN predicate defines the subtrees; and so on. Here are some common queries that you can use to build others:
ÎÒÃÇ¿ÉÒÔÀûÓÃһЩ¿ÉÔ¤¼ûµÄ½á¹û¹¹½¨²éѯ£¨±í´ïʽ£©¡£¸ù²¿×ÜÊÇÒÔÕâÖÖÐÎʽ¹¹³É£¨left = 1, right = 2 * (SELECT COUNT(*) from TreeTable)£©£»Ò¶×Ó½ÚµãÔò×ÜÊÇ£¨left + 1 = right£©£»BETWEEN±í´ï¶¨ÒåÁË×ÓÊ÷£»µÈµÈ¡£ÕâÀïÓÐһЩ³£ÓõIJéѯ£¬Äã¿ÉÒÔÓÃËüÃÇÀ´×齨¸ü¶àÆäËû£¨²éѯ£©£º
1. Find an employee and all his/her supervisors, no matter how deep the tree.
²éÕÒÒ»¸ö¹ÍÔ±¼°Ëû/ËýµÄËùÓÐÉϼ¶£¬ÎÞÂÛÕâ¿ÅÊ÷½á¹¹ÓжàÉî¡£
SELECT P2.*
from Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
AND P1.emp = :myemployee;
2. Find the employee and all his/her subordinates. (This query has a nice symmetry with the first query.)
²éÕÒ¹ÍÔ±¼°Ëû/ËýËùÓÐÏÂÊô¡££¨Õâ¸ö²éѯÓëµÚÒ»¸ö²éѯÐγÉÁ¼ºÃµÄ¶Ô³Æ¡££©
SELECT P2.*
from Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
AND P2.emp = :myemployee;
3. Add a GROUP BY and aggregate functions to these basic queries and you have hierarchical reports. For example, the total salaries that each employee controls:
¸øÕâЩ»ù±¾²éѯÌí¼ÓGROUP BY£¨¹Ø¼ü×Ö£©ºÍ×ܼƺ¯ÊýÕâÑùÄã¾ÍÓзּ¶¼Ç¼ÁË¡£ÀýÈ磬ÿ¸ö¹ÍÔ±ÄÜÖ§ÅäµÄн³ê×ÜÊý£º
SELECT P2.emp, SUM(S1.salary)
from Personnel AS P1, Personnel AS P2,
Salaries AS S1
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
AND P1.emp = S1.emp
GROUP BY P2.emp;
In the adjacency list method, this has to be done with a cursor.
ÔÚÁÚ½ÓÁбíģʽÀ±ØÐëÒÀ¿¿Óα꣨cursor£©²ÅÄÜÕâÑù×ö¡£
4. Find the level of each node, so you can print the tree as an indented listing.
²éÕÒÿ¸ö½ÚµãµÄ¼¶±ð£¬ÕâÑùÄã¾ÍÄܹ»ÒÔËõ½øÁбíÐÎʽ´òÓ¡Õâ¿ÃÊ÷ÁË¡£
SELECT COUNT(P2.emp) AS indentation, P1.emp
from Personnel AS P1, Personnel AS P2
WHERE P1.lft BETWEEN P2.lft AND P2.rgt
GROUP BY P1.emp
ORDER BY P1.lft;
5. The nested set mod


Ïà¹ØÎĵµ£º

SQL Express×Ô¶¯±¸·Ý

--µÚÒ»²½
--ÔÚmaster¿âÖн¨Á¢Ò»¸ö±¸·ÝÊý¾Ý¿âµÄ´æ´¢¹ý³Ì.
USE master
GO
CREATE PROC p
      @db_name sysname,         --Êý¾Ý¿âÃû
      @bk_path NVARCHAR(1024)     --±¸·ÝÎļþµÄ·¾¶
 A ......

ASP.NETÁ¬½ÓSQLºÍACCESSµÄ·½·¨

SQL:
using System.Data.SqlClient;
string sql = "server=.;uid=sa;pwd=;database=tablename;";
ACCESS:
using System.Data.OleDb;
string sql = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA Source=" + HttpRuntime.AppDomainAppPath + "//App_Data//db.mdb";
HttpRuntime.AppDomainAppPath Ϊ¸ùĿ¼
......

sql server µÄ bcp µ¼Èëµ¼³ö

  Ò»£¬
bcpÃüÁîÏê½â
  bcpÃüÁîÊÇSQL ServerÌṩµÄÒ»¸ö¿ì½ÝµÄÊý¾Ýµ¼Èëµ¼³ö¹¤¾ß¡£Ê¹ÓÃËü²»ÐèÒªÆô¶¯ÈκÎͼÐιÜÀí¹¤¾ß¾ÍÄÜÒÔ¸ßЧµÄ·½Ê½µ¼Èëµ¼³öÊý¾Ý¡£bcpÊÇSQL ServerÖиºÔðµ¼Èëµ¼³öÊý¾ÝµÄÒ»¸öÃüÁîÐй¤¾ß£¬ËüÊÇ»ùÓÚDB-LibraryµÄ£¬²¢ÇÒÄÜÒÔ²¢Ðеķ½Ê½¸ßЧµØµ¼Èëµ¼³ö´óÅúÁ¿µÄÊý¾Ý¡£bcp¿ÉÒÔ½«Êý¾Ý¿âµÄ±í»òÊÓͼֱ½Óµ¼³ö ......

JSP + SQL server 2000¿ª·¢»·¾³µÄ´î½¨

     ´Ó×òÌ쿪ʼ¾ÍÒ»Ö±ÔÚÍøÉϲéÕÒÊý¾Ý¿âΪSQL server 2000 µÄJSP¿ª·¢»·¾³µÄ´î½¨£¬µ½ÏÖÔÚΪֹÖÕÓÚÄܹ»Õý³£Áª½Ó²¢·ÃÎÊ¡£ÒÔÏÂÊǴµÄ²½Ö裺
1¡¢´ÓÍøÉÏÏÂÔØÒ»¸öSQL server 2000 ¸öÈ˰æµÄ°²×°°ü£¬°´ÕÕÌáʾ²Ù×÷£¬µ±ÔÚÉí·ÖÑé֤ʱ£¬Ñ¡Ôñ»ìºÏģʽ£¬Óû§saµÄÃÜÂë¿ÉÒÔΪ¿Õ£¬Ò²¿ÉÒÔ²»Îª¿Õ¡£
2¡¢´ÓÍøÉÏÏÂÔØÒ»¸öSQ ......

SQL Server Ë÷Òý½á¹¹¼°ÆäʹÓã¨Èý£©

ʵÏÖСÊý¾ÝÁ¿ºÍº£Á¿Êý¾ÝµÄͨÓ÷ÖÒ³ÏÔʾ´æ´¢¹ý³Ì
¡¡¡¡½¨Á¢Ò»¸ö Web Ó¦Ó㬷ÖÒ³ä¯ÀÀ¹¦Äܱز»¿ÉÉÙ¡£Õâ¸öÎÊÌâÊÇÊý¾Ý¿â´¦ÀíÖÐÊ®·Ö³£¼ûµÄÎÊÌâ¡£¾­µäµÄÊý¾Ý·ÖÒ³·½·¨ÊÇ:ADO ¼Í¼¼¯·ÖÒ³·¨£¬Ò²¾ÍÊÇÀûÓÃADO×Ô´øµÄ·ÖÒ³¹¦ÄÜ£¨ÀûÓÃÓα꣩À´ÊµÏÖ·ÖÒ³¡£µ«ÕâÖÖ·ÖÒ³·½·¨½öÊÊÓÃÓÚ½ÏСÊý¾ÝÁ¿µÄÇéÐΣ¬ÒòΪÓα걾ÉíÓÐȱµã£ºÓαêÊÇ´æ·ÅÔÚÄÚ´æÖУ¬º ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ