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

»ùÓÚmssql °ÙÍò¼¶ Êý¾Ý ²éѯ ÓÅ»¯ ¼¼ÇÉÈýÊ®Ôò

1.¶Ô²éѯ½øÐÐÓÅ»¯£¬Ó¦¾¡Á¿±ÜÃâÈ«±íɨÃ裬Ê×ÏÈÓ¦¿¼ÂÇÔÚ where ¼° order by Éæ¼°µÄÁÐÉϽ¨Á¢Ë÷Òý¡£
2.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐÐ null ÖµÅжϣ¬·ñÔò½«µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬È磺
select id from t where num is null
¿ÉÒÔÔÚnumÉÏÉèÖÃĬÈÏÖµ0£¬È·±£±íÖÐnumÁÐûÓÐnullÖµ£¬È»ºóÕâÑù²éѯ£º
select id from t where num=0
3.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖÐʹÓÃ!=»ò<>²Ù×÷·û£¬·ñÔò½«ÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£
4.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖÐʹÓà or À´Á¬½ÓÌõ¼þ£¬·ñÔò½«µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃ裬È磺
select id from t where num=10 or num=20
¿ÉÒÔÕâÑù²éѯ£º
select id from t where num=10
union all
select id from t where num=20
5.in ºÍ not in Ò²ÒªÉ÷Ó㬷ñÔò»áµ¼ÖÂÈ«±íɨÃ裬È磺
select id from t where num in(1,2,3)
¶ÔÓÚÁ¬ÐøµÄÊýÖµ£¬ÄÜÓà between ¾Í²»ÒªÓà in ÁË£º
select id from t where num between 1 and 3
6.ÏÂÃæµÄ²éѯҲ½«µ¼ÖÂÈ«±íɨÃ裺
select id from t where name like '%abc%'
ÈôÒªÌá¸ßЧÂÊ£¬¿ÉÒÔ¿¼ÂÇÈ«ÎļìË÷¡£
7.Èç¹ûÔÚ where ×Ó¾äÖÐʹÓòÎÊý£¬Ò²»áµ¼ÖÂÈ«±íɨÃè¡£ÒòΪSQLÖ»ÓÐÔÚÔËÐÐʱ²Å»á½âÎö¾Ö²¿±äÁ¿£¬µ«ÓÅ»¯³ÌÐò²»Äܽ«·ÃÎʼƻ®µÄÑ¡ÔñÍƳٵ½ÔËÐÐʱ£»Ëü±ØÐëÔÚ±àÒëʱ½øÐÐÑ¡Ôñ¡£È»¶ø£¬Èç¹ûÔÚ±àÒëʱ½¨Á¢·ÃÎʼƻ®£¬±äÁ¿µÄÖµ»¹ÊÇδ֪µÄ£¬Òò¶øÎÞ·¨×÷ΪË÷ÒýÑ¡ÔñµÄÊäÈëÏî¡£ÈçÏÂÃæÓï¾ä½«½øÐÐÈ«±íɨÃ裺
select id from t where num=@num
¿ÉÒÔ¸ÄΪǿÖƲéѯʹÓÃË÷Òý£º
select id from t with(index(Ë÷ÒýÃû)) where num=@num
8.Ó¦¾¡Á¿±ÜÃâÔÚ where ×Ó¾äÖжÔ×ֶνøÐбí´ïʽ²Ù×÷£¬Õ⽫µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£È磺
select id from t where num/2=100
Ó¦¸ÄΪ:
select id from t where num=100*2
9.Ó¦¾¡Á¿±ÜÃâÔÚwhere×Ó¾äÖжÔ×ֶνøÐк¯Êý²Ù×÷£¬Õ⽫µ¼ÖÂÒýÇæ·ÅÆúʹÓÃË÷Òý¶ø½øÐÐÈ«±íɨÃè¡£È磺
select id from t where substring(name,1,3)='abc'--nameÒÔabc¿ªÍ·µÄid
select id from t where datediff(day,createdate,'2005-11-30')=0--‘2005-11-30’Éú³ÉµÄid
Ó¦¸ÄΪ:
select id from t where name like 'abc%'
select id from t where createdate>='2005-11-30' and createdate<'2005-12-1'
10.²»ÒªÔÚ where ×Ó¾äÖеē=”×ó±ß½øÐк¯Êý¡¢ËãÊõÔËËã»òÆäËû±í´ïʽÔËË㣬·ñÔòϵͳ½«¿ÉÄÜÎÞ·¨ÕýȷʹÓÃË÷Òý¡£
11.ÔÚʹÓÃË÷Òý×Ö¶Î×÷ΪÌ


Ïà¹ØÎĵµ£º

Linux»·¾³µÄAMP°²×° MSSQLÀ©Õ¹°²×°


LinuxÒª°²×°mssqlÀ©Õ¹£¬±ØÐëÊ×ÏÈ°²×°freetds£¬°²×°¹ý³ÌÈçÏ£º
1¡¢¼ÙÉèÔ´ÎļþĿ¼Ϊ/webServ£¬°²×°Ä¿Â¼Îª/opt/freetds¡£
1) >cd /webServ
2) ÏÂÔØ£¬ >wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
3) ½âѹ£¬ >tar -zxvf freetds-stable.tgz
4) ½øÈ룬 >cd freetds-0¡£ ......

ÐÞ¸ÄMSSQL±íËùÓÐÕßµÄÁ½ÖÖ·½·¨

ÍøÕ¾¸ü»»¿Õ¼äµÄʱºò£¬¾­³£»áÒòΪMSSQLÊý¾Ý¿âÃû²»Í¬£¬µ¼Ö´Ӿɿռ䱸·ÝµÄÊý¾Ý¿âÔÚпռ仹ԭºóÎÞ·¨Õý³£Ê¹Óá£Õâʱºò£¬ÎÒÃÇ¿ÉÒÔͨ¹ý½«Êý¾Ý¿â±íµÄËùÓÐÕßÐÞ¸ÄΪ"dbo"À´½â¾öÕâ¸öÎÊÌ⣬¾ßÌåµÄ·½·¨ÈçÏ£º
´ò¿ª"Microsoft SQL Server"µÄ“ÆóÒµ¹ÜÀíÆ÷”£¬µã¿ªÒªÐ޸ĵÄÊý¾Ý¿â£¬Ñ¡Ôñ¹¤¾ßÀ¸Éϵē¹¤¾ß” ......

MSSQL ½øÖÆת»»

-- ÈÎÒâ½øÖÆת»»Îª10½øÖÆ
-- Àý 0FA ת»»Îª 16½øÖÆ select dbo.f_BinaryToInt('0123456789ABCDEF', '0FA')
CREATE   function   dbo.f_BinaryToInt(@BinaryFormate varchar(100), @num   varchar(200))  
--@BinaryFormate Ϊ×Ô¶¨ÒåµÄ½øÖƸñʽ
--@num ΪҪת»»³É10½øÖƵÄ×Ô¶¨ ......

c# ²Ù×÷mssqlÊý¾Ý¿â º¬Óдø²ÎÊýsqlÓï¾äÔËÐÐ

<?xml version="1.0" encoding="utf-8"?>
<configuration>
 <appSettings>
  <add key="Default" value="Default" />
 </appSettings>
 <connectionStrings>
  <add name="Default" connectionString="Data Source=192.168.1.197;User ID ......

MsSql ²é¿´ÐÅÏ¢ºÃÓï¾ä

set statistics profile on
set statistics io on
set statistics time on
select top 1 * from et_order order by pkid desc
½á¹ûÈçÏ£º
SQL Server ·ÖÎöºÍ±àÒëʱ¼ä:
   CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
SQL Server Ö´ÐÐʱ¼ä:
   CPU ʱ¼ä = 0 ºÁÃ룬ռÓÃʱ¼ä = 1 ºÁÃë¡£
SQL Se ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ