SQLÓï¾ä´óÈ«(2)
ÔÚ½øÐÐÊý¾Ý¿â²Ù×÷ʱ£¬Î޷ǾÍÊÇÌí¼Ó¡¢É¾³ý¡¢Ð޸ģ¬ÕâµÃÉè¼Æµ½Ò»Ð©³£ÓõÄSQLÓï¾ä£¬ÈçÏ£º
SQL³£ÓÃÃüÁîʹÓ÷½·¨£º
(1) Êý¾Ý¼Ç¼ɸѡ£º
sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû=×Ö¶ÎÖµ order by ×Ö¶ÎÃû [desc]"
sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû like %×Ö¶ÎÖµ% order by ×Ö¶ÎÃû [desc]"
sql="select top 10 * from Êý¾Ý±í where ×Ö¶ÎÃû order by ×Ö¶ÎÃû [desc]"
sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû in (Öµ1,Öµ2,Öµ3)"
sql="select * from Êý¾Ý±í where ×Ö¶ÎÃû between Öµ1 and Öµ2"
(2) ¸üÐÂÊý¾Ý¼Ç¼£º
sql="update Êý¾Ý±í set ×Ö¶ÎÃû=×Ö¶ÎÖµ where Ìõ¼þ±í´ïʽ"
sql="update Êý¾Ý±í set ×Ö¶Î1=Öµ1,×Ö¶Î2=Öµ2 …… ×Ö¶În=Öµn where Ìõ¼þ±í´ïʽ"
(3) ɾ³ýÊý¾Ý¼Ç¼£º
sql="delete from Êý¾Ý±í where Ìõ¼þ±í´ïʽ"
sql="delete from Êý¾Ý±í" (½«Êý¾Ý±íËùÓмǼɾ³ý)
(4) Ìí¼ÓÊý¾Ý¼Ç¼£º
sql="insert into Êý¾Ý±í (×Ö¶Î1,×Ö¶Î2,×Ö¶Î3 …) valuess (Öµ1,Öµ2,Öµ3 …)"
sql="insert into Ä¿±êÊý¾Ý±í select * from Ô´Êý¾Ý±í" (°ÑÔ´Êý¾Ý±íµÄ¼Ç¼Ìí¼Óµ½Ä¿±êÊý¾Ý±í)
(5) Êý¾Ý¼Ç¼ͳ¼Æº¯Êý£º
AVG(×Ö¶ÎÃû) µÃ³öÒ»¸ö±í¸ñÀ¸Æ½¾ùÖµ
COUNT(*|×Ö¶ÎÃû) ¶ÔÊý¾ÝÐÐÊýµÄͳ¼Æ»ò¶ÔijһÀ¸ÓÐÖµµÄÊý¾ÝÐÐÊýͳ¼Æ
MAX(×Ö¶ÎÃû) È¡µÃÒ»¸ö±í¸ñÀ¸×î´óµÄÖµ
MIN(×Ö¶ÎÃû) È¡µÃÒ»¸ö±í¸ñÀ¸×îСµÄÖµ
SUM(×Ö¶ÎÃû) °ÑÊý¾ÝÀ¸µÄÖµÏà¼Ó
ÒýÓÃÒÔÉϺ¯ÊýµÄ·½·¨£º
sql="select sum(×Ö¶ÎÃû) as ±ðÃû from Êý¾Ý±í where Ìõ¼þ±í´ïʽ"
set rs=conn.excute(sql)
Óà rs("±ðÃû") »ñȡͳµÄ¼ÆÖµ£¬ÆäËüº¯ÊýÔËÓÃͬÉÏ¡£
(6) Êý¾Ý±íµÄ½¨Á¢ºÍɾ³ý£º
CREATE TABLE Êý¾Ý±íÃû³Æ(×Ö¶Î1 ÀàÐÍ1(³¤¶È),×Ö¶Î2 ÀàÐÍ2(³¤¶È) …… )
Àý£ºCREATE TABLE tab01(name varchar(50),datetime default now())
DROP TABLE Êý¾Ý±íÃû³Æ (ÓÀ¾ÃÐÔɾ³ýÒ»¸öÊý¾Ý±í)
MSSQL¾µäÓï¾ä
1.°´ÐÕÊϱʻÅÅÐò:Select * from TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as
2.Êý¾Ý¿â¼ÓÃÜ:select encrypt('ÔʼÃÜÂë')
select pwdencrypt('ÔʼÃÜÂë')
select pwdcompare('ÔʼÃÜÂë','¼ÓÃܺóÃÜÂë') = 1--Ïàͬ£»·ñÔò²»Ïàͬ encrypt('ÔʼÃÜÂë')
select pwdencrypt('ÔʼÃÜÂë')
select pwdcompare('ÔʼÃÜÂë','¼ÓÃܺóÃÜÂë') = 1--Ïàͬ£»·ñÔò²»Ïàͬ
3.È¡»Ø±íÖÐ×Ö¶Î:declare @list varchar(1000),@sql nvarchar(1000)
select @list=@list+','+b.name fr
Ïà¹ØÎĵµ£º
²éѯËÙ¶ÈÂýµÄÔÒòºÜ¶à£¬³£¼ûÈçϼ¸ÖÖ£º
¡¡¡¡1¡¢Ã»ÓÐË÷Òý»òÕßûÓÐÓõ½Ë÷Òý(ÕâÊDzéѯÂý×î³£¼ûµÄÎÊÌ⣬ÊdzÌÐòÉè¼ÆµÄȱÏÝ)
¡¡¡¡2¡¢I/OÍÌÍÂÁ¿Ð¡£¬ÐγÉÁËÆ¿¾±Ð§Ó¦¡£
¡¡¡¡3¡¢Ã»Óд´½¨¼ÆËãÁе¼Ö²éѯ²»ÓÅ»¯¡£
¡¡¡¡4¡¢ÄÚ´æ²»×ã
¡¡¡¡5¡¢ÍøÂçËÙ¶ÈÂý
¡¡¡¡6¡¢²éѯ³öµÄÊý¾ÝÁ¿¹ý´ó(¿ÉÒÔ²ÉÓöà ......
oracle³£ÓþµäSQL²éѯ
³£ÓÃSQL²éѯ£º
1¡¢²é¿´±í¿Õ¼äµÄÃû³Æ¼°´óС
select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
2¡¢²é¿´±í¿Õ¼äÎïÀíÎļþµÄÃû³Æ ......
ORACLE SQLÐÔÄÜÓÅ»¯´ó×ܽá
1£© Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
" ?; J) n+ v8 J- v" q OracleµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡ ......
Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:mssql7backupMyNwind_1.dat'
--- ¿ªÊ¼ ±¸·Ý
BACKUP DATABASE pubs TO testBack ......
±¾ÎĽÚÑ¡×Ô¡¶Oracle DBAÊּǗ—Êý¾Ý¿âÕï¶Ï°¸ÀýÓëÐÔÄÜÓÅ»¯Êµ¼ù¡·µÚ2Õ“YangtingkunµÄDBA¹¤×÷Êּǔ £¨×÷ÕߣºÑîÍ¢çû£©
V$SQLÊÓͼÏÔʾ½á¹ûÒì³£µÄÕï¶Ï
ÓÐÒ»´ÎÅöµ½Ò»¸öºÜÆæ¹ÖµÄÎÊÌ⣬ÔÚ¼ì²é»á»°ËùÖ´ÐеÄSQLʱ£¬·¢ÏÖV$SQLÊÓͼÖÐSQL_TEXTÁÐÖеÄÊý¾ÝÊDz»Õý³£µÄ¡£
ÓÉÓÚV$SQLÊǶ¯Ì¬ÐÔÄÜÊÓͼ£¬ÀïÃæ±£´æµÄÊǵ± ......