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

SQL²éѯÓï¾äʹÓÃ

Ò»¡¢¼òµ¥²éѯ
¡¡¡¡ ¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣
ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ
±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
SELECT nickname,email
from testtable WHERE name='ÕÅÈý'
(Ò»)Ñ¡ÔñÁбí
¡¡¡¡Ñ¡ÔñÁбí(select_list)Ö¸³öËù²éѯÁУ¬Ëü¿ÉÒÔÊÇÒ»×éÁÐÃûÁÐ±í¡¢ÐǺš¢±í´ïʽ¡¢±äÁ¿(°üÀ¨¾Ö²¿±ä Á¿ºÍÈ«¾Ö±äÁ¿)µÈ¹¹³É¡£
¡¡¡¡ 1¡¢Ñ¡ÔñËùÓÐÁÐ ÀýÈ磬ÏÂÃæÓï¾äÏÔʾtesttable±íÖÐËùÓÐÁеÄÊý¾Ý£º SELECT * from testtable
¡¡¡¡ 2¡¢Ñ¡Ôñ²¿·ÖÁв¢Ö¸¶¨ËüÃǵÄÏÔʾ´ÎÐò ²éѯ½á¹û¼¯ºÏÖÐÊý¾ÝµÄÅÅÁÐ˳ÐòÓëÑ¡ÔñÁбíÖÐËùÖ¸¶¨µÄÁÐÃûÅÅÁÐ˳ÐòÏàͬ¡£
ÀýÈ磺 SELECT nickname,email from testtable
¡¡¡¡ 3¡¢¸ü¸ÄÁбêÌâ ÔÚÑ¡ÔñÁбíÖУ¬¿ÉÖØÐÂÖ¸¶¨ÁбêÌâ¡£¶¨Òå¸ñʽΪ£º ÁбêÌâ=ÁÐÃû ÁÐÃû ÁбêÌâ Èç¹ûÖ¸¶¨µÄÁбêÌâ²»ÊDZê×¼µÄ±êʶ·û¸ñʽʱ£¬Ó¦Ê¹ÓÃÒýºÅ¶¨½ç·û¡£
ÀýÈ磬ÏÂÁÐÓï¾äʹÓúº×ÖÏÔʾÁÐ ±êÌ⣺ SELECT êdzÆ=nickname,µç×ÓÓʼþ=email from testtable
¡¡¡¡ 4¡¢É¾³ýÖظ´ÐÐ SELECTÓï¾äÖÐʹÓÃALL»òDISTINCTÑ¡ÏîÀ´ÏÔʾ±íÖзûºÏÌõ¼þµÄËùÓÐÐлòɾ³ýÆäÖÐÖظ´µÄÊý¾ÝÐУ¬Ä¬ÈÏ ÎªALL¡£Ê¹ÓÃDISTINCTÑ¡Ïîʱ£¬¶ÔÓÚËùÓÐÖظ´µÄÊý¾ÝÐÐÔÚSELECT·µ»ØµÄ½á¹û¼¯ºÏÖÐÖ»±£ÁôÒ»ÐС£
¡¡¡¡ 5¡¢ÏÞÖÆ·µ»ØµÄÐÐÊý ʹÓÃTOP n [PERCENT]Ñ¡ÏîÏÞÖÆ·µ»ØµÄÊý¾ÝÐÐÊý£¬TOP n˵Ã÷·µ»ØnÐУ¬¶øTOP n PERCENTʱ£¬ËµÃ÷nÊÇ ±íʾһ°Ù·ÖÊý£¬Ö¸¶¨·µ»ØµÄÐÐÊýµÈÓÚ×ÜÐÐÊýµÄ°Ù·ÖÖ®¼¸¡£
ÀýÈ磺 SELECT TOP 2 * from testtable SELECT TOP 20 PERCENT * from testtable
(¶þ)from×Ó¾ä
¡¡¡¡from×Ó¾äÖ¸¶¨SELECTÓï¾ä²éѯ¼°Óë²éѯÏà¹ØµÄ±í»òÊÓͼ¡£ÔÚfrom×Ó¾äÖÐ×î¶à¿ÉÖ¸¶¨256¸ö±í»òÊÓͼ£¬ ËüÃÇÖ®¼äÓöººÅ·Ö¸ô¡£ ÔÚfrom×Ó¾äͬʱָ¶¨¶à¸ö±í»òÊÓͼʱ£¬Èç¹ûÑ¡ÔñÁбíÖдæÔÚͬÃûÁУ¬ÕâʱӦʹÓöÔÏóÃûÏÞ¶¨ÕâЩÁÐ ËùÊôµÄ±í»òÊÓͼ¡£
ÀýÈçÔÚusertableºÍcitytable±íÖÐͬʱ´æÔÚcityidÁУ¬ÔÚ²éѯÁ½¸ö±íÖеÄcityidʱӦʹÓÃÏÂÃæÓï¾ä¸ñʽ¼ÓÒÔÏÞ¶¨£º
¡¡SELECT username,citytable.cityid
¡¡from usertable,citytable
¡¡WHERE usertable.cityid=citytable.cityid
ÔÚfrom×Ó¾äÖпÉÓÃÒÔÏÂÁ½ÖÖ¸ñʽΪ±í»òÊÓͼָ¶¨±ðÃû£º ±íÃû as ±ðÃû ±íÃû ±ðÃû
ÀýÈçÉÏÃæÓï¾ä¿ÉÓñíµÄ±ðÃû¸ñʽ±íʾΪ£º
SELECT username,b.cityid
from usertable a,citytable b
WHERE a.cityid=b.cityid
SELECT²»½öÄÜ´Ó±í»òÊÓͼÖмìË÷Êý¾Ý£¬Ë


Ïà¹ØÎĵµ£º

SQL Server 2000½Ì²Ä¶ÁÊé±Ê¼Ç£¨1£©

  ºÜ¾Ã֮ǰ¾ÍÏëÒª°Ñ×Ô¼ºµÄ¶ÁÊé¹ý³Ì¼Ç¼ÏÂÀ´£¬½ñÌìÉÔ΢ÕûÀíÁËһϣ¬ÈÏΪ²»¹ÜʲôÊ飬×Ô¼ºÃ»ÔõôÍêÕûµØ¿´Í꣬¸ü±ðÌáÈÏÕæµØÈ«²¿µØ¿´ÍêÁË¡£ÌýÈË˵£¬ÒªÑ¡1±¾ºÃÊéÀ´¿´£¬ÎÒ²»·´¶ÔÕâÖÖ˵·¨£¬µ«¸üÖØÒªµÄÊÇ£¬²»½öÊÇÊé±¾Éí£¬¶øÊÇÎÒÃÇ×Ô¼ºµÄÇé¿ö£¬ÊDz»ÊÇÕæÕýͶÈë½øÈ¥¿´ÁË£¬²»¹ÜÔõÑù£¬Ð´ÊéµÄÈ˵Ä֪ʶ¿Ï¶¨±ÈÄãÕâ·½ÃæµÄ֪ʶҪ¶®ºÜ¶à£¬ ......

¾­µäSQLÓï¾ä´óÈ«

ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
¡¡¡¡SQL·ÖÀࣺ
¡¡¡¡DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
¡¡¡¡DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
¡¡¡¡DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
¡¡¡¡Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
¡¡¡¡1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
......

SQL Server 2005 ÎÊÌ⣺TCP/IPÎÞ·¨Á¬½Ó

 ¸ÕÅöµ½Õâ¸öÎÊÌâʱ£¬ÒÔΪÊÇÓ¦Ó÷þÎñÆ÷ºÍÊý¾Ý¿â·þÎñÆ÷ûÁ¬Í¨£¬²éÁË°ëÌìµÄÍøÂç½á¹ûÍøÉÏÒ»²é£¬¸úSQL Server 2005Óйأ¬ÄãÌ«ÑôµÄ£¡
  ¿ªÊ¼²Ëµ¥-SQLServer2005-ÅäÖù¤¾ß-SQL Server Configuration Manager-SQLserver2005ÍøÂçÅäÖÃ-MSSQLSERVERµÄЭÒé-Ë«»÷TCP/IPЭÒé
  °ÑIP¸Ä³Éµ±Ç°Ê¹Óõģ¬µ±È»£¬¶Ë¿ÚҲҪȷ±£ ......

.NET »ñÈ¡¾ÖÓòÍøµÄsql server Áбí

SqlDataSourceEnumerator instance =SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();
»ò
System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources();
·µ»ØDatatable
´Ëtable°üº¬ÒÔÏÂËĸö×Ö¶Î
Console.WriteLine("·þÎñÆ÷Ãû = {0}", r ......

sql³£ÓÃÓï¾ä

ÔÚSQLSERVER£¬¼òµ¥µÄ×éºÏsp_spaceusedºÍsp_MSforeachtableÕâÁ½¸ö´æ´¢¹ý³Ì£¬¿ÉÒÔ·½±ãµÄͳ¼Æ³öÓû§Êý¾Ý±íµÄ´óС£¬°üÀ¨¼Ç¼×ÜÊýºÍ¿Õ¼äÕ¼ÓÃÇé¿ö£¬·Ç³£ÊµÓã¬ÔÚSqlServer2KºÍSqlServer2005Öж¼²âÊÔͨ¹ý¡£
/*
1. exec sp_spaceused '±íÃû'            £¨SQLͳ¼ÆÊý¾Ý£¬´óÁ¿ÊÂÎñ²Ù×÷ºó¿É ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ