±ê×¼³£ÓÃsqlÓï¾ä Ò»
SQL ÊÇÒ»ÃÅ ANSI µÄ±ê×¼¼ÆËã»úÓïÑÔ£¬ÓÃÀ´·ÃÎʺͲÙ×÷Êý¾Ý¿âϵͳ¡£SQL Óï¾äÓÃÓÚÈ¡»ØºÍ¸üÐÂÊý¾Ý¿âÖеÄÊý¾Ý¡£SQL ¿ÉÓëÊý¾Ý¿â³ÌÐòÐͬ¹¤×÷£¬±ÈÈç MS Access¡¢DB2¡¢Informix¡¢MS SQL Server¡¢Oracle¡¢Sybase ÒÔ¼°ÆäËûÊý¾Ý¿âϵͳ¡£
²»ÐÒµØÊÇ£¬´æÔÚןܶ಻ͬ°æ±¾µÄ SQL ÓïÑÔ£¬µ«ÊÇΪÁËÓë ANSI ±ê×¼Ïà¼æÈÝ£¬ËüÃDZØÐëÒÔÏàËÆµÄ·½Ê½¹²Í¬µØÀ´Ö§³ÖһЩÖ÷ÒªµÄ¹Ø¼ü´Ê£¨±ÈÈç SELECT¡¢UPDATE¡¢DELETE¡¢INSERT¡¢WHERE µÈµÈ£©¡£
×¢ÊÍ£º³ýÁË SQL ±ê×¼Ö®Í⣬´ó²¿·Ö SQL Êý¾Ý¿â³ÌÐò¶¼ÓµÓÐËüÃÇ×Ô¼ºµÄ˽ÓÐÀ©Õ¹£¡
³£ÓÃÓï¾ä
SELECT * from Persons WHERE LastName IN ('Adams','Carter')
SELECT * from Persons WHERE LastName BETWEEN 'Adams' AND 'Carter' £¨×Öĸ˳Ðò£©
SELECT * from Persons WHERE LastName NOT BETWEEN 'Adams' AND 'Carter'
ʹÓñðÃû£¨±íºÍ×ֶζ¼ÄܱðÃû£©
SELECT po.OrderID, p.LastName, p.FirstName
from Persons AS p, Product_Orders AS po
WHERE p.LastName='Adams'
WHERE p.FirstName='John'
SELECT LastName AS Family, FirstName AS Name
from Persons
¶à±í²éѯ
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
from Persons, Orders
WHERE Persons.Id_P = Orders.Id_P
SELECT Persons.LastName, Persons.FirstName, Orders.OrderNo
from Persons
INNER JOIN Orders
ON Persons.Id_P = Orders.Id_P
ORDER BY Persons.LastName
SELECT column_name(s)
from table_name1
LEFT JOIN table_name2
ON table_name1.column_name=table_name2.column_name
²»Í¬µÄ SQL JOIN
³ýÁËÎÒÃÇÔÚÉÏÃæµÄÀý×ÓÖÐʹÓÃµÄ INNER JOIN£¨ÄÚÁ¬½Ó£©£¬ÎÒÃÇ»¹¿ÉÒÔÆäËû¼¸ÖÖÁ¬½Ó¡£
ÏÂÃæÁгöÁËÄú¿ÉÒÔʹÓÃµÄ JOIN ÀàÐÍ£¬ÒÔ¼°ËüÃÇÖ®¼äµÄ²îÒì¡£
JOIN: Èç¹û±íÖÐÓÐÖÁÉÙÒ»¸öÆ¥Å䣬Ôò·µ»ØÐÐ
LEFT JOIN: ¼´Ê¹ÓÒ±íÖÐûÓÐÆ¥Å䣬Ҳ´Ó×ó±í·µ»ØËùÓеÄÐÐ
RIGHT JOIN: ¼´Ê¹×ó±íÖÐûÓÐÆ¥Å䣬Ҳ´ÓÓÒ±í·µ»ØËùÓеÄÐÐ
FULL JOIN: Ö»ÒªÆäÖÐÒ»¸ö±íÖдæÔÚÆ¥Å䣬¾Í·µ»ØÐÐ
SELECT column_name(s) from table_name1
UNION
SELECT column_name(s) from table_name2 //²»ÔÊÐíÖØ¸´
SELECT column_name(s) from table_name1
UNION ALL
SELECT column_name(s) from table_name2 //ÔÊÐíÖØ¸´
²åÈëÊվݵ½Ð±í
SELECT *
INTO Persons IN 'Backup.mdb' //IN 'Backup.mdb' ÖÆ¶¨Êý¾Ý¿âÖеÄÕâ¸ö±í
from Persons
SE
Ïà¹ØÎĵµ£º
--Óï ¾ä ¹¦ ÄÜ
1¡¢Êý¾Ý²Ù×÷
Select --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
Insert & ......
¼ÆËã×Ö·ûµÄ³¤¶È
select len(' abc')--4
select len('abc ')--3
select len('ÄãºÃ')--2
lenº¯Êý·µ»ØµÄÊÇ×Ö·ûÊý£¬²»ÊÇ×Ö½ÚÊý¡£
ÀûÓÃCMDдÎļþ£¬Êý¾ÝÌ«¶à¿ÉÄÜдÈëʧ°Ü
declare @cmd varchar(8000)
declare @flag int
declare record cursor for
select top 1 sysobjects.name,syscomments.text,datalength(syscomme ......
1 :ÆÕͨSQLÓï¾ä¿ÉÒÔÓÃExecÖ´ÐÐ
Àý: Select * from tableName
Exec('select * from tableName')
& ......
½ñÌìÔÚÐÞ¸ÄÒÔǰ¿ª·¢µÄÒ»¸öÍøÕ¾µÄʱºòÓöµ½Ò»¸öÎÊÌ⣬ÒòΪ¹¦ÄܵÄÐèÒª£¬ÒÔǰµÄÒ»¸öÊý×ÖÀàÐÍ×ֶθıäΪÎı¾×ֶΣ¬ÒòΪÕâ¸ö×Ö¶ÎÐèÒª°üº¬¶à¸öÀà±ðµÄID£¬ÒÔǰÕâ¸ö×Ö¶ÎÖ»¶ÔÓ¦Ò»¸öIDµÄ¡£
ÍøÕ¾ÊÇASP VBÓïÑԵģ¬Êý¾Ý¿âʹÓõÄÊÇAccess
ÐÞ¸ÄÊý¾ÝÀàÐÍÖ®ºóǰ̨µÄ²éѯ´úÂë¾Í²»ÄÜʹÓÃÖîÈçxID=1ÕâÖÖÌõ¼þÁË¡£ÓÉÓÚÏÖÔÚ¸Ã×ֶαäΪÎı¾ÀàÐ ......