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

SQLÓïÑÔ»ù´¡

SQL:Structured Query Language,1974ÄêBoyceºÍChamberlinÌá³ö.
Êý¾Ý¶¨Òå :CREATE,DROP
Êý¾Ý¿â²éѯ:SELECT
Êý¾Ý²Ù×Ý :INSERT,UPDATE,DELETE
Êý¾Ý¿ØÖÆ :GRANT,REVOKE
Ò».Êý¾ÝµÄ¶¨ÒåºÍÐÞ¸Ä:
1.¶¨Òå»ù±í
CREATE TABLE ±íÃû (<ÁÐÃû1 ÀàÐÍ[NOT NULL][,ÁÐÃû2 ÀàÐÍ[NOT NULL]>…[ÆäËû²ÎÊý]);
¹ØÓÚÀàÐÍ:
INTEGER È«×Ö³¤µÄ¶þ½øÖÆÕûÊý.
SMALLINT °ë×Ö³¤µÄ¶þ½øÖÆÕûÊý.
DECIMAL(p[,q])ѹËõÊ®½øÖÆÊý,¹²pλСÊýµãºóÓÐqλ,15>=p>=q>=0,q=0ʱ¿ÉÊ¡ÂÔ.
FLOAT Ë«×Ö³¤µÄ¸¡µãÊý.
CHAR(n) ³¤¶ÈΪnµÄ¶¨³¤×Ö·û´®.
VARCHAR(n)±ä³¤×Ö·û´®,×î´ó³¤Îªn.
2.Ð޸Ļù±í
ALTER TABLE ±íÃû ADD ÁÐÃû ÀàÐÍ; //Ôö¼ÓÐÂÁÐ.
3.ɾ³ý»ù±í
DROP TABLE ±íÃû; //ɾ³ý»ù±íÁ¬Í¬±íÖмǼ.
¶þ.ÊÓͼµÄ¶¨Òå
1.¶¨ÒåÊÓͼ
CREATE VIEW ÊÓͼÃû[ÁÐÃû[,ÁÐÃû]…]AS ×Ó²éѯ[WITH CHECK OPTION];
2.ÊÓͼɾ³ý
DROP VIEW ÊÓͼÃû;
Èý.Êý¾Ý²Ù×Ý
SELECT [DISTINCT] Ñ¡ÔñÊä³öÊôÐÔ±í
from Òª¼ìË÷µÄ±íÃû
[WHERE ¼ìË÷Ó¦Âú×ãµÄÌõ¼þ]
[GROUP BY ·Ö×éÊôÐÔ±í(HAVING ¼ìË÷Ìõ¼þ)]
[ORDER BY ÅÅÐòÊôÐÔ±í];
1. ¼òµ¥²éѯ
(1).²»Ïû³ýÖظ´Ôª×éµÄ¼ìË÷
SELECT TITLE from BOOKS
(2).Ïû³ýÖظ´Ôª×éµÄ¼ìË÷
SELECT DISTINCT TITLE from BOOKS
(3).ʹÓÔ*”È«²¿¼ìË÷
SELECT * from BOOKS
(4).´ø±í´ïʽµÄ¼ìË÷
SELECT TITLE , PRICE*3 from BOOKS WHERE TITLE=’²Ù×÷ϵͳ’
(5).ÒªÇóÅÅÐòµÄ¼ìË÷
SELECT CARD-NO,TITLE,DATA from BOOKS
WHERE DATA<1998.7.1 ORDER BY CARD-NO ASC|DESC //Éý»ò½µ
2. º¬Óи÷ÖÖν´ÊµÄ¼ìË÷
COMPARISON, IN, LIKE, NULL, QUANTIFIED, EXISTS, BETWEEN
(1).BETWEEN
SELECT TITLE,SORT-NO,LO-NO from BOOKS WHERE LO-NO
BETWEEN 4 AND 5µÈ¼ÛÓÚ
SELECT TITLE,SORT-NO,LO-NO from BOOKS WHERE LO-NO
>=4 AND LO-NO<=5
(2).IN ͬÉÏÀý:
SELECT TITLE,SORT-NO,LO-NO from BOOKS WHERE LO-NO
IN(4,5) ´ËÀý»¹¿Éд³É:
SELECT TITLE,SORT-NO,LO-NO from BOOKS WHERE LO-NO
=4 OR LO-NO=5
(3).LIKE:ÕÒ³öÐÕÕŵÄÇé¿ö
SELECT NAME,CARD-NO,DEPT from BOOKS WHERE NAME
LIKE’ÕÅ%’ //ÊôÐÔÃûÀàÐÍÒ»¶¨ÎªCHAR;¶ÌÏß“-”±íʾ´ËλΪһ¸ö×Ö·û;
“%”±íʾÈÎÒâ×Ö·û´®(º¬¿Õ´®);ÆäËü×Ö·û´ú±í×ÔÉí.
3. Áª½Ó²éѯ
(1).µÈÖµÁª½Ó
SELECT BORROWERS.*,LOANS.CARD-NO,LOANS.TITLE
from BORROWERS


Ïà¹ØÎĵµ£º

sql ÖÐcaseÓ÷¨

Case¾ßÓÐÁ½ÖÖ¸ñʽ¡£¼òµ¥Caseº¯ÊýºÍCaseËÑË÷º¯Êý¡£
--¼òµ¥Caseº¯Êý
CASE sex
         WHEN '1' THEN 'ÄÐ'
         WHEN '2' THEN 'Å®'
ELSE 'ÆäËû' END
--CaseËÑË÷º¯Êý
CASE WHEN sex = '1' THEN 'ÄÐ'
     ......

SQLÓïÑÔ»ù´¡ Êý¾Ý¶¨Òå

1¡¢¶¨Òå»ù±¾±í
SQLÓïÑÔʹÓö¯´ÊCREATE¶¨Òå»ù±¾±í£¬Æä¾ßÌåÓï·¨¸ñʽÈçÏ£º
CREATE TABLE <±íÃû>
(<ÁÐÃû><Êý¾ÝÀàÐÍ>[Áм¶ÍêÕûÐÔÔ¼ÊøÌõ¼þ]...[£¬<ÁÐÃû><Êý¾ÝÀàÐÍ>[Áм¶ÍêÕûÐÔÔ¼ÊøÌõ¼þ]][,<±í¼¶ÍêÕûÐÔÔ¼ÊøÌõ¼þ>])£»
ÀýÈ磺½¨Á¢Ò»¸öѧÉú±íStudent£¬ËüÓÉѧºÅSno£¬ÐÕÃûSname£¬ÐÔ±ðSsex£¬Äê ......

SQL Server²éѯÓÅ»¯

MS SQL Server²éѯÓÅ»¯·½·¨
×÷Õߣºxmllover 2007-11-29 
²éѯËÙ¶ÈÂýµÄÔ­ÒòºÜ¶à£¬³£¼ûÈçϼ¸ÖÖ 
  1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ) 
  2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£ 
  3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£ 
  4¡¢ÄÚ´æ ......

SQL Server ¾­Ñé £¨×ªÔØ£©

SQL Server ¾­Ñé £¨×ªÔØ£©
http://www.cnblogs.com/treeyh/archive/2007/08/06/844763.html
Èç¹ûÄãÕýÔÚ¸ºÔðÒ»¸ö»ùÓÚSQL ServerµÄÏîÄ¿£¬»òÕßÄã¸Õ¸Õ½Ó´¥SQL Server£¬Ä㶼ÓпÉÄÜÒªÃæÁÙһЩÊý¾Ý¿âÐÔÄܵÄÎÊÌ⣬ÕâƪÎÄÕ»áΪÄãÌṩһЩÓÐÓõÄÖ¸µ¼£¨ÆäÖдó¶àÊýÒ²¿ÉÒÔÓÃÓÚÆäËüµÄDBMS£©¡£
   ÔÚÕâÀÎÒ²»´òËã½éÉ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ