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

²âÊÔÈËÔ±ÒªÕÆÎյĻù±¾µÄSQLÓï¾ä(ÉÏ)

²âÊÔÈËÔ±ÒªÕÆÎյĻù±¾µÄSQLÓï¾ä(ÉÏ)
 
 
 
 
                                              
                                               MSN:nanans126@hotmail.com
2008-11-14        Nancy
 
Ŀ¼  
Ò»¡¢DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)  
¶þ¡¢DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)  
Èý¡¢DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE)
ËÄ¡¢Ï°벿·ÖÄÚÈÝ(Ö÷ÒªÊÇPL/SQL:º¯Êý£¬´æ´¢¹ý³Ì£¬ÊÂÎñµÈ)
 
˵Ã÷£º±¾ÎĵµµÄʹÓöÔÏóÊǶÔSQLÓÐһЩÁ˽âµÄÈí¼þ²âÊÔÈËÔ±£¬ÎÒÖ»ÊÇ°ÑÎÒÖªµÀµÄ֪ʶ½áºÏÍøÉϵÄ×ÊÁϽøÐжþ´Î×ܽᣬ²»ÕýÖ®´¦Íû¶àÇë½Ì¡£±¾ÎĵµÅäÖø½ÓÐSQL·¶Àý½Å±¾¡£
Ò»¡¢DDLÊý¾Ý¶¨ÒåÓïÑÔ
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£¬×÷Ϊ²âÊÔÈËÔ±Ò»°ã²âÊÔʱ£¬ÒѾ­ÓÉÊý¾Ý¿âÉè¼Æʦ½¨ºÃÁËÊý¾Ý¿â£¬Êý¾Ý¿âÉè¼Æʦ¿ÉÄÜÒ²²»ÓÃÓï¾äµÄ·½Ê½À´½¨±í£¬µ«ÎÒÃÇÓ¦¸ÃÄÜ¿´¶®¸÷Óï¾äµÄʹÓøñʽ£¬Óï¾äµÄº¬Ò壬ÓÐÐËȤÔÙ×÷ÉîÈëÁ˽⡣
1¡¢´´½¨Êý¾Ý¿â
CREATE DATABASE [database-name] 
2¡¢É¾³ýÊý¾Ý¿â
DROP DATABASE dbname1,dbname2…
 
3¡¢±¸·ÝÊý¾Ý¿â
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- ¿ªÊ¼ ±¸·Ý
BACKUP DATABASE pubs TO testBack  
4¡¢´´½¨±í
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
ÀýÈç: CREATE TABLE S
(SNO CHAR(10) NOT NULL ,
SN VARCHAR(20),
AGE INT,
SEX CHAR(2) DEFAULT 'ÄÐ' ,
DEPT VARCHAR(20));
¸ù¾ÝÒÑÓÐµÄ±í´´½¨ÐÂ±í£º  
A£ºcreate table tab_new like tab_old (ʹÓÃ¾É±í´´½¨Ð±í)
B£ºcreate table tab_new as s


Ïà¹ØÎĵµ£º

sql³£ÓÃ

select [name] from sysdatabases order by name--µÃµ½Êý¾Ý¿âÖÐËùÓеĿâÃû
select [name] from sysobjects where xtype='U'and [name]<>'dtproperties' order by [name]--µÃµ½Êý¾Ý¿â±íÖеÄÁбí
select [name] from sysobjects where xtype='V' and [name]<>'syssegments' and [name]<>'sysconstraints' ......

SQL Server 2005 ²éѯ·ÖÎöÖÐɾ³ýÊý¾Ý¿â

USE   master  
GO
DECLARE   @dbname   sysname  
SET  @dbname='TEST' --Õâ¸öÊÇҪɾ³ýµÄÊý¾Ý¿â¿âÃû  
DECLARE @s  NVARCHAR(1000)  
DECLARE tb CURSOR local FOR  
SELECT s='KILL '+CAST(spid AS NVARCHAR)&nbs ......

SQL ѧϰ±Ê¼Ç ¶à¹Ø¼ü×ÖÅÅÐò

ÈçºÎʵÏÖ¶à¸ö¹Ø¼ü×Ö°´ÕÕ²»Í¬ÅÅÐò¹æÔò½øÐÐÅÅÐòÄØ£¿
ORDER BY×Ó¾äÈÃÊý¾Ý¿â¶Ô²éѯ½á¹ûÅÅÐò£¬ORDER BY×Ó¾ä±ØÐë·ÅÔÚ²éѯÓï¾äµÄ½áβ¡£Æä»ù±¾ÓÃ
·¨ÈçÏ£º 
SELECT * from Contacts ORDER BY first_name; 
Äã¿ÉÒÔ¶Ô¶àÁÐÊý¾ÝÅÅÐò¡£ÓÅÏÈ˳Ðò°´´Ó×óµ½ÓÒÒÀ´Î½µµÍ£¬ËùÒÔ²éѯÓï¾äÖ ......

sqlÖظ´Êý¾Ý´¦Àí£¬ÓÐΨһID£¬formidÓÐÖظ´,ÁôÒ»Ìõ

/*sqlÖظ´Êý¾Ý´¦Àí£¬ÓÐΨһID£¬formidÓÐÖظ´*/
/*²é³öÖظ´µÄfromid*/
select formid from GaiaSaver_BUG group by formid having count(*)>1
/*ɾ³ýÖظ´formid£¬Ö»ÁôÒ»Ìõ*/
delete from GaiaSaver_BUG  where ID not in
(select   min(ID) as ID  from  GaiaSaver_BUG  group by for ......

SQL¶à¼¶¹ØϵµÄ±íʾ

ÎÒÃÇÒª½¨Á¢¶à¼¶¹Øϵ£¬Ê×ÏÈÐèÒªÁ½¸ö±í.
        µÚÒ»¸ö±í±íʾֱÊô½á¹¹£¬±ÈÈç˵ÎÒÃǹ«Ë¾ÓÐÒ»¸ö²¿ÃÅ¡£¶øÕâ¸ö²¿ÃÅÏ»¹ÓÐ3¸öС×飬ÄÇô3¸öС×éÊôÓÚÕâ¸ö²¿ÃÅ.µÚ¶þ¸ö±í±íʾ¶à²ã½á¹¹,¾ÍÏóµÚÒ»±íÀïÃæËù±íʾµÄ£¬ÕâÈý¸öС×éͬʱ»¹ÊôÓÚ¹«Ë¾.¶øÕâ¸ö¹«Ë¾Í¬Ê±ÊôÓÚÕâ3¸öС×éµÄ¸¸¼¶µÄ¸¸¼¶µÄ²¿ÃÅ¡£¼ÙÈçÎÒ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ