Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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 ±ðÃû
±íÃû ±ðÃû
(¶þ) from×Ó¾ä
from×Ó¾äÖ¸¶¨SELECTÓï¾ä²éѯ¼°Óë²éѯÏà¹ØµÄ±í»òÊÓͼ¡£ÔÚfrom×Ó¾äÖÐ×î¶à¿ÉÖ¸¶¨256¸ö±í»òÊÓͼ£¬
ËüÃÇÖ®¼äÓöººÅ·Ö¸ô¡£
ÔÚfrom×Ó¾äͬʱָ¶¨¶à¸ö±í»òÊÓͼʱ£¬Èç¹ûÑ¡ÔñÁбíÖдæÔÚͬÃûÁ


Ïà¹ØÎĵµ£º

µÚ2 ÕÂ SQL ÎÊÌâ

2.1 ±¾ÕÂÄ¿µÄ
ÔÚ±¾ÕÂÖоÍÔÚ HSQLDB Ö÷Ò³ÂÛ̳»òÓʼþÁбíÖжà´ÎÌá³öµÄÎÊÌâ½øÐнâ´ð£¬Èç¹ûÄã´òËãÔÚÓ¦
ÓóÌÐòÖÐʹÓÃHSQLDB µÄ»°£¬ÄãÓ¦¸ÃÔĶÁһϱ¾Õ¡£
2.2 ¶ÔSQL ±ê×¼µÄÖ§³Ö
1.8.0 °æ±¾µÄHSQLDB Ö§³ÖSQL92¡¢99 ºÍ2003 ±ê×¼¹æ¶¨µÄSQL ·½ÑÔ¡£ÕâÒâζ×ÅHSQLDB
ÖÐÖ§³ÖµÄ±ê×¼ÌØÐÔ£¨ÀýÈç×óÍâÁ¬½Ó£©µÄÓï·¨ÊÇÓɱê×¼Îı¾¹æ¶¨µÄ¡£Ðí¶ ......

SQL Server 2005µ¼ÈëºÍµ¼³ö

ÔÚ SQL Server Management Studio ÖУ¬Á¬½Óµ½Êý¾Ý¿âÒýÇæ·þÎñÆ÷ÀàÐÍ£¬Õ¹¿ªÊý¾Ý¿â£¬ÓÒ¼üµ¥»÷Ò»¸öÊý¾Ý¿â£¬Ö¸Ïò“ÈÎÎñ”£¬ÔÙµ¥»÷“µ¼ÈëÊý¾Ý”»ò“µ¼³öÊý¾Ý”¡£
»òÕß
¿ªÊ¼²¢Ñ¡ÔñÔËÐв¢ÊäÈëCMD È»ºóÔÚÃüÁîÌáʾ·ûÀïÊäÈëDTSWIZARD¡£
»ò
ÔÚÃüÁîÌáʾ·û´°¿ÚÖÐÔËÐÐ DTSWizard.exe£¨Î»ÓÚ C:\Program ......

ÍêȫжÔØSQL Server 2005

 
1.ÐèÒªÒ»ÖÖÏÂÔØжÔع¤¾ß£¬ÕâÀïÑ¡Ôñ΢Èí¹Ù·½ÌṩµÄ¹¤¾ß(msicuu2.exe)
http://support.microsoft.com/default.aspx?kbid=290301
 
2.ʹÓÃжÔع¤¾ßжÔØËùÓÐSQL Server·þÎñºÍÏà¹Ø×é¼þ(×¢Ò⣺жÔØÇ°ÒªÏÈÍ£Ö¹¶ÔÓ¦µÄ·þÎñ£¬·ñÔò¿ÉÄÜжÔØʧ°Ü)
 
3.ɾ³ýC:\WINDOWS\inf ÏÂËùÓÃÎļþ(ÎÒÊÇÔÚ¸ÃÎļþ¼ÐÏÂËÑË÷&ldquo ......

sql server 2008 bcp ÅúÁ¿¸´ÖƳÌÐò ³ö´í ½â¾ö

sql server 2008 bcp ÅúÁ¿¸´ÖƳÌÐò ³ö´í
C:\Documents and Settings>bcp MSPetShop4.dbo.product out c:\1.txt -T
SQLState = 08001, NativeError = -1
Error = [Microsoft][SQL Native Client]SQL ÍøÂç½Ó¿Ú: ¶¨Î»Ö¸¶¨µÄ Server/Instance
ʱ³ö´í [xFFFFFFFF].
SQLState = HYT00, NativeError = 0
Error = [Micros ......

PL/SQLµÄÊý¾ÝÀàÐͺͳ£Óú¯Êý

1£©PL/SQLÊý¾ÝÀàÐÍ
Ãû³Æ
ÀàÐÍ
˵Ã÷
NUMBER
Êý×ÖÐÍ
ÄÜ´æ·ÅÕûÊýÖµºÍʵÊýÖµ£¬²¢ÇÒ¿ÉÒÔ¶¨Ò徫¶ÈºÍÈ¡Öµ·¶Î§
BINARY_INTEGER
Êý×ÖÐÍ
¿É´æ´¢´ø·ûºÅÕûÊý£¬ÎªÕûÊý¼ÆËãÓÅ»¯ÐÔÄÜ
DEC
Êý×ÖÐÍ
NUMBERµÄ×ÓÀàÐÍ£¬Ð¡Êý
DOUBLE PRECISION
Êý×ÖÐÍ
NUMBERµÄ×ÓÀàÐÍ£¬¸ß¾«¶ÈʵÊý
INTEGER
Êý×ÖÐÍ
NUMBERµÄ×ÓÀàÐÍ£¬ÕûÊý
INT
Êý ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ