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

SQLÓαê¿ìËÙÉÏÊÖ

ÎÊÌâÃèÊö£ºÓÐÒÔÏÂ2ÕÅ±í£¬
     ±íA
     0_id           0_name      0_Salary
   Y2007001     ´ï¸ç            3666
   Y2007002      С¶Å           4888
   Y2007003        ´ï¸ç         3666
     ±íB
  a_id               a_salary
 Y2007001        333
Y2007002          444
Y2007003          555      
ÏÖÔÚÏ£ÍûµÃµ½ÕâÑùµÄÊý¾Ý±íAÀïµÄO_Saloary¼ÓÉϱíBµÄA_SalaryÊǵ±Ç°µÄ×ܹ¤×Ê£¬²¢¸üе½±íA¡£
       Äã¿ÉÒÔÓÃÊÓͼÀ´£¬±íÁ¬½ÓϾͿÉÒÔ¡£
       ÏÖÔÚÎÒÃÇ¿¼ÂÇÏÂÈÃSQL×Ô¼ºÀ´´¦Àí£¬Óαê¾ÍÊǺܺõķ½·¨¡£
      
      Ô­Àí£ºÓαê¾ÍÊǰÑÊý¾Ý°´ÕÕÖ¸¶¨ÒªÇóÌáÈ¡³öÏàÓ¦µÄÊý¾Ý¼¯£¬È»ºóÖðÌõ½øÐÐÊý¾Ý´¦Àí¡£
      1.1ÓαêµÄ¸ÅÄî
       Óαê(Cursor)ËüʹÓû§¿ÉÖðÐзÃÎÊÓÉSQL Server·µ»ØµÄ½á¹û¼¯¡£Ê¹ÓÃÓαê(cursor)µÄÒ»¸öÖ÷ÒªµÄÔ­Òò¾ÍÊǰѼ¯ºÏ²Ù×÷ת»»³Éµ¥¸ö¼Ç¼´¦Àí·½Ê½¡£ÓÃSQLÓïÑÔ´ÓÊý¾Ý¿âÖмìË÷Êý¾Ýºó£¬½á¹û·ÅÔÚÄÚ´æµÄÒ»¿éÇøÓòÖУ¬ÇÒ½á¹ûÍùÍùÊÇÒ»¸öº¬Óжà¸ö¼Ç¼µÄ¼¯ºÏ¡£Óαê»úÖÆÔÊÐíÓû§ÔÚSQL serverÄÚÖðÐеطÃÎÊÕâЩ¼Ç¼£¬°´ÕÕÓû§×Ô¼ºµÄÒâÔ¸À´ÏÔʾºÍ´¦ÀíÕâЩ¼Ç¼¡£
       1.2 ÓαêµÄÓŵã
      ´ÓÓα궨Òå¿ÉÒԵõ½ÓαêµÄÈçÏÂÓŵ㣬ÕâЩÓŵãʹÓαêÔÚʵ¼ÊÓ¦ÓÃÖз¢»ÓÁËÖØÒª×÷Óãº
        1£©ÔÊÐí³ÌÐò¶ÔÓɲéѯÓï¾äselect·µ»ØµÄÐм¯ºÏÖеÄÿһÐÐÖ´ÐÐÏàͬ»ò


Ïà¹ØÎĵµ£º

SQLÓï¾ä ´´½¨Ë÷Òý

Óï·¨£º
CREATE [Ë÷ÒýÀàÐÍ] INDEX Ë÷ÒýÃû³Æ
ON ±íÃû(ÁÐÃû)
WITH FILLFACTOR = Ìî³äÒò×ÓÖµ0~100
GO
/*ʵÀý*/
USE ¿âÃû
GO
IF EXISTS
(SELECT * from SYSINDEXES WHERE NAME='IX_TEST_TNAME')--¼ì²âÊÇ·ñÒѾ­´æÔÚIX_TEST_TNAMEË÷Òý
DROP INDEX
TEST.IX_TEST_TNAME--Èç¹û´æÔÚÔòɾ³ý
--´´½¨Ë÷Òý
CREATE NONCLUSTER ......

SQL ServerÖС°¼ÓËøÑ¡ÏµÄ¹¦ÄÜ˵Ã÷

1   ÈçºÎËøÒ»¸ö±íµÄijһÐÐ  
   
   
  A   Á¬½ÓÖÐÖ´ÐÐ  
   
  SET   TRANSACTION   ISOLATION   LEVEL   REPEATABLE   READ  
   
  begin   tran  
   
  selec ......

ÅäÖÃODBCÁ¬²»ÉÏSQL ServerµÄ½â¾ö·½·¨

1¡¢¸ÃÓû§ÓеǼȨÏÞ¡£
2¡¢ServerÈç¹û¿ªÁËFirewall£¬ÔÚexceptionsÀïÌí¼Ó1433 port ¡£
3¡¢ÅäÖù¤¾ß->SQL ServerÍâΧӦÓÃÅäÖÃÆ÷->·þÎñºÍÁ¬½ÓµÄÍâΧӦÓÃÅäÖÃÆ÷->´ò¿ªMSSQLSERVER½ÚµãÏ嵀 Database Engine ½Úµã£¬Ñ¡Ôñ“Ô¶³ÌÁ¬½Ó”£¬½ÓϽ¨ÒéÑ¡Ôñ"ͬʱʹÓÃTCP/IPºÍnamed pipes"£¬È·¶¨ºó£¬ÖØÆôÊý¾Ý¿â·þÎñºó ......

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

 ½«Ä³ÖÖÊý¾ÝÀàÐ͵ıí´ïʽÏÔʽת»»ÎªÁíÒ»ÖÖÊý¾ÝÀàÐÍ¡£CAST ºÍ CONVERT ÌṩÏàËÆµÄ¹¦ÄÜ¡£
Óï·¨
ʹÓà CAST£º
CAST ( expression AS data_type )
ʹÓà CONVERT£º
CONVERT (data_type[(length)], expression [, style])
²ÎÊý
expression
ÊÇÈκÎÓÐЧµÄ Microsoft® SQL Server™ ±í´ïʽ¡£Óйظü¶àÐÅÏ¢£¬Çë² ......

ת£ºsqlÓï¾äʵÏÖ·ÖÒ³»ã×Ü

Ó¦Ò»¸öÅóÓѵÄÒªÇó£¬ÌùÉÏÊղصÄSQL³£Ó÷ÖÒ³µÄ°ì·¨¡«¡«
±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
  (SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
  from ±íÃû
  ORDER BY ID))
  O ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ