SQL Server Óï¾ä
1.SELECTÓï¾ä´ÓÊý¾Ý¿âÖÐѡȡÊý¾Ý
SELECT 'ÁÐÃû' from '±íÃû' SELECT list_name from table_name ´Ó '±íÃû' Ñ¡Çø'ÁÐÃû' Êý¾Ý SQL SELECT * from table_name ´Ó '±íÃû' Ñ¡ÇøÈ«²¿Êý¾Ý
2.SELECT ¼ÓWHERE Óï¾ä
SELECT 'ÁÐÃû' from '±íÃû' WHERE 'Ìõ¼þ'
3.SELECT ¼ÓAS Óï¾ä
ʹÓÃAS ¸øÊý¾ÝÖ¸¶¨Ò»¸ö±ðÃû¡£´Ë±ðÃûÓÃÀ´ÔÚ±í´ïʽÖÐʹÓà count()º¯ÊýµÄ×÷ÓÃÊÇ£º¼ÆËãÊý×éÖеÄÔªËØÊýÄ¿»ò¶ÔÏóÖеÄÊôÐÔ¸öÊý¡£ SELECT CONCAT(*) AS new_name
4.SELECT JOIN ONÓï¾ä
JOINÁªºÏ²Ù×÷Á½¸ö±í SELECT 'ÁÐÃû1' 'ÁÐÃû2' from '±íÃû1' JOIN '±íÃû2' ON Ìõ¼þ SELECT A.SYMBOL,A.SNAME from SECURITYCODE A JOIN DAYQUOTE B ON A.SYMBOL =B.SYMBOL SQL--JOINÖ®ÍêÈ«Ó÷¨(°æ±¾2)
5.SELECT ORDER BYÓï¾ä
ORDER BYÅÅÐòASCÉýÐò, DESC½µÐò SELECT 'ÁÐÃû' from '±íÃû1' ORDER BY 'ÁÐÃû' [ASC, DESC] SELECT list_name from table_name Orders ORDER BY list_name
6.SELECT LIMITÓï¾ä
SELECT * from table LIMIT [offset,] rows | rows OFFSET offset LIMIT ·µ»ØÖ¸¶¨µÄ¼Ç¼Êý¡£LIMIT ½ÓÊÜÒ»¸ö»òÁ½¸öÊý×Ö²ÎÊý¡£²ÎÊý±ØÐëÊÇÒ»¸öÕûÊý³£Á¿¡£Èç¹û¸ø¶¨Á½¸ö²ÎÊý£¬µÚÒ»¸ö²ÎÊýÖ¸¶¨µÚÒ»¸ö·µ»Ø¼Ç¼ÐÐµÄÆ«ÒÆÁ¿£¬µÚ¶þ¸ö²ÎÊýÖ¸¶¨·µ»Ø¼Ç¼ÐеÄ×î´óÊýÄ¿¡£³õʼ¼Ç¼ÐÐµÄÆ«ÒÆÁ¿ÊÇ 0(¶ø²»ÊÇ 1)£º SELECT * from table LIMIT 5,10; // ¼ìË÷¼Ç¼ÐÐ 6-15 //ΪÁ˼ìË÷´Óijһ¸öÆ«ÒÆÁ¿µ½¼Ç¼¼¯µÄ½áÊøËùÓеļǼÐУ¬¿ÉÒÔÖ¸¶¨µÚ¶þ¸ö²ÎÊýΪ -1£º SELECT * from table LIMIT 95,-1; // ¼ìË÷¼Ç¼ÐÐ 96-last. //Èç¹ûÖ»¸ø¶¨Ò»¸ö²ÎÊý£¬Ëü±íʾ·µ»Ø×î´óµÄ¼Ç¼ÐÐÊýÄ¿£º SELECT * from table LIMIT 5; //¼ìË÷ǰ 5 ¸ö¼Ç¼ÐÐ //»»¾ä»°Ëµ£¬LIMIT n µÈ¼ÛÓÚ LIMIT 0,n¡£
ºÍ´ó¼ÒÒ»ÆðѧϰSQLµÄINSERT INTO\UPDATE\DELETE²Ù×÷Óï¾ä£º
1.INSERT INTO
INSERT INTO ±íÃû VALUES (Öµ1, Öµ2,....) ½«Öµ1£¬Öµ2£¬ ²åÈë' ±íÃû' ÖеÄÒ»ÐÐÖµ INSERT INTO ±íÃû (ÁÐ1, ÁÐ2,...) VALUES (Öµ1, Öµ2,....) Ö¸¶¨ÁвåÈëÊý¾Ý
2.UPDATE
UPDATE ±íÃû SET ÁÐÃû = 'Öµ2' WHERE ÁÐÃû = 'Öµ1' ÔÚ±íÖн«ÔÁÐֵΪֵ1µÄ£¬ÉèÖÃΪֵ2
2.DELETE
DELETE from ±íÃû WHERE ÁÐÃû = 'Öµ1' ɾ³ýÁÐÃûֵΪֵ1µÄÐÐ DELETE from ±íÃû WHERE ÁÐÃû = 'Öµ1' DELETE * from ±íÃû DELETE from ±íÃû ɾ³ý±íÃûËùÓеÄÐÐ
Ïà¹ØÎĵµ£º
1.sp_helpsort
SELECT SERVERPROPERTY ('Collation')
²é¿´ÄãµÄÅÅÐò¹æÔò.
²»¹ýÄãµÄÕâ¸öÓ¦¸ÃºÍ×Ö·û¼¯ÓйØ.
2.¸ü¸Ä·þÎñÆ÷ÅÅÐò¹æÔò
¸ü¸Ä SQL Server 2005 ʵÀýµÄĬÈÏÅÅÐò¹æÔòµÄ²Ù×÷¿ÉÄÜ»á±È½Ï¸´ÔÓ£¬°üÀ¨ÒÔϲ½Ö裺
È·±£¾ßÓÐÖØÐ´´½¨Óû§Êý¾Ý¿â¼°ÕâЩÊý¾Ý¿âÖеÄËùÓжÔÏóËùÐèµÄÈ«²¿ÐÅÏ¢»ò½Å±¾¡£
ʹÓù¤¾ß£¨ÀýÈç´óÈÝÁ ......
¹Ì¶¨³¤¶È(char)Óë¿É±ä³¤¶È(varchar)×Ö·ûÊý¾ÝÀàÐÍ
char[(n)]
³¤¶ÈΪn¸ö×ֽڵĹ̶¨³¤¶ÈÇÒ·ÇUnicodeµÄ×Ö·ûÊý¾Ý¡£n±ØÐëÊÇÒ»¸ö½éÓÚ1ºÍ8,000Ö®¼äµÄÊýÖµ¡£´æ´¢´óСΪn¸ö×Ö½Ú¡£charÔÚSQL-92ÖеÄͬÒå´ÊΪcharacter¡£
varchar[(n)]
³¤¶ÈΪn¸ö×ֽڵĿɱ䳤¶ÈÇÒ·ÇUnicodeµÄ×Ö·ûÊý¾Ý¡£n±ØÐëÊÇÒ»¸ö½éÓÚ1ºÍ8,000Ö®¼äµÄÊýÖµ¡£´æ´¢´óСΪ ......
ͨ¹ýv$sqlarea,v$sql²éѯ×îÕ¼ÓÃ×ÊÔ´µÄ²éѯ ÊÕ²Ø
ÒýÓÃ:http://blog.chinaunix.net/u/3866/showart_396335.html
-----------------------
v$sqlarea,v$sql
-----------------------
´ÓV$SQLAREAÖвéѯ×îÕ¼ÓÃ×ÊÔ´µÄ²éѯ
select b.username username,a.disk_reads reads,
a.executions exec,a ......
¡¾IT168 ¼¼Êõ·ÖÎö¡¿ÔÚÏò2009Äê¸æ±ðÖ®¼Ê£¬ÎÒÃÇÀ´»Ø¹ËһϹýÈ¥µÄÒ»ÄêÖÐ×îÊÜ»¶ÓµÄSQL Server¼¼ÇÉ£¬°üÀ¨ÁËOPENROWSET¡¢FILESTREAMµÈº¯ÊýµÄÓ÷¨¡¢ÃÜÂ빤¾ß½éÉÜÒÔ¼°DBAÈÕ³£¹¤×÷½¨ÒéµÈÄÚÈÝ¡£
¡¡¡¡Í¨¹ý¶ÔÕâЩ¾«»ªÎÄÕµÄÔٴλعˣ¬Ï£Íû¿ÉÒÔ°ïÖúÄúÊáÀíÒ»ÏÂÕâÒ»ÄêÒÔÀ´µÄ¹¤×÷ÒÔ¼°Ñ§Ï°Ðĵ㬶ÔδÀ´Ò»Äê¸ü½øÒ»²½´òϸü¼áʵµÄ»ù´¡¡£
¡¡¡ ......