¾µäsqlÓï¾ä
¾µäSQLÓï¾ä´óÈ«
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
¡¡¡¡SQL·ÖÀࣺ
¡¡¡¡DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
¡¡¡¡DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
¡¡¡¡DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
¡¡¡¡Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
¡¡¡¡1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
¡¡¡¡2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
¡¡¡¡3¡¢ËµÃ÷£º±¸·Ýsql server
¡¡¡¡--- ´´½¨ ±¸·ÝÊý¾ÝµÄ 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],..)
¡¡¡¡¸ù¾ÝÒÑÓÐµÄ±í´´½¨ÐÂ±í£º
A£ºcreate table tab_new like tab_old (ʹÓÃ¾É±í´´½¨Ð±í)
B£ºcreate table tab_new as select col1,col2… from tab_old definition only
¡¡¡¡5¡¢ËµÃ÷£º
¡¡¡¡É¾³ýÐÂ±í£ºdrop table tabname
¡¡¡¡6¡¢ËµÃ÷£º
¡¡¡¡Ôö¼ÓÒ»¸öÁУºAlter table tabname add column col type
¡¡¡¡×¢£ºÁÐÔö¼Óºó½«²»ÄÜɾ³ý¡£DB2ÖÐÁмÓÉϺóÊý¾ÝÀàÐÍÒ²²»Äܸı䣬ΨһÄܸıäµÄÊÇÔö¼ÓvarcharÀàÐ͵ij¤¶È¡£
¡¡¡¡7¡¢ËµÃ÷£º
¡¡¡¡Ìí¼ÓÖ÷¼ü£ºAlter table tabname add primary key(col)
¡¡¡¡ËµÃ÷£º
¡¡¡¡É¾³ýÖ÷¼ü£ºAlter table tabname drop primary key(col)
¡¡¡¡8¡¢ËµÃ÷£º
¡¡¡¡´´½¨Ë÷Òý£ºcreate [unique] index idxname on tabname(col….)
¡¡¡¡É¾³ýË÷Òý£ºdrop index idxname
¡¡¡¡×¢£ºË÷ÒýÊDz»¿É¸ü¸ÄµÄ£¬Ïë¸ü¸Ä±ØÐëɾ³ýÖØн¨¡£
¡¡¡¡9¡¢ËµÃ÷£º
¡¡¡¡´´½¨ÊÓͼ£ºcreate view viewname as select statement
¡¡¡¡É¾³ýÊÓͼ£ºdrop view viewname
10¡¢ËµÃ÷£º¼¸¸ö¼òµ¥µÄ»ù±¾µÄsqlÓï¾ä
¡¡¡¡Ñ¡Ôñ£ºselect * from table1 where ·¶Î§
¡¡¡¡²åÈ룺insert into table1(field1,field2) values(value1,value2)
¡¡¡¡É¾³ý£ºdelete from table1 where ·¶Î§
¡¡¡¡¸üУºupdate table1 set field1=value1 where ·¶Î§
¡¡¡¡²éÕÒ£ºselect * from table1 where field1 like ’%value1%’ ---likeµÄÓï·¨ºÜ¾«Ã²é×ÊÁÏ!
¡¡¡¡ÅÅÐò£ºselect * from table1 order by field1,field2 [desc]
¡¡¡¡×ÜÊý£ºselect count * as totalcount from table1
¡¡¡¡ÇóºÍ£ºselect sum(field1) as su
Ïà¹ØÎĵµ£º
--´ÓExcelÎļþÖÐ,µ¼ÈëÊý¾Ýµ½SQLÊý¾Ý¿âÖÐ,ºÜ¼òµ¥,Ö±½ÓÓÃÏÂÃæµÄÓï¾ä:
/*===================================================================*/
--Èç¹û½ÓÊÜÊý¾Ýµ¼ÈëµÄ±íÒѾ´æÔÚ
insert into ±í select * from
OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 5.0;HDR=YES;DATABASE=c:\test.xls',sheet1$)
--Èç ......
1. ¶¨ÒåÓα궨Òå
ÓαêÓï¾äµÄºËÐÄÊǶ¨ÒåÁËÒ»¸öÓαê±êʶÃû£¬²¢°ÑÓαê±êʶÃûºÍÒ»¸ö²éѯÓï¾ä¹ØÁªÆðÀ´¡£DECLAREÓï¾äÓÃÓÚÉùÃ÷Óα꣬Ëüͨ¹ýSELECT²éѯ¶¨ÒåÓαê´æ´¢µÄÊý¾Ý¼¯ºÏ¡£Óï¾ä¸ñʽΪ£º
DECLARE ÓαêÃû³Æ [INSENSITIVE] [SCROLL]
CURSOR FOR selectÓï¾ä
[FOR{READ ONLY|UPDATE[OF ÁÐÃû×Ö±í]}]
²ÎÊý˵Ã÷£º
INSENS ......
ÔÚ20ÊÀ¼Í70Äê´ú³õÆÚ£¬IBMÑо¿Ô±E. F. Codd²©Ê¿¿ª´´ÐÔµØÑо¿¿ª·¢Á˹ØϵÊý¾ÝÄ£ÐͲúÆ·SEQUEL£¬¼´½á¹¹»¯Ó¢Óï²éѯÓïÑÔ£¨Structured English Query Language£©¡£SEQUEL×îÖÕ±ä³ÉÁËSQL£¬»ò½á¹¹»¯²éѯÓïÑÔ£¨Structured Query Language£¬SQL£©¡£
IBM¼°ÆäËû¹ØϵÊý¾Ý¿âµÄ¿ª·¢³§É̶¼Ï£ÍûÓÐÒ»Ì×ÄÜ·ÃÎʲ¢²Ù×ݹØϵÊý¾Ý¿âµÄ±ê×¼»¯·½ ......
×öÊý¾Ý¿âµ÷ÓÅ£¬Ò»¸ö¼òµ¥µÄtip¾ÍʹÐÔÄÜÌáÉýÒ»´ó¿éʱ£¬±»°ïÖúµÄÈË×ÔÈ»ÊǸßÐ˶øÇҸм¤£¬ÎÒÒ²ÊÇÂúÐÄ»¶Ï²¡£ÓÃËùѧ°ïÖúÁËËûÈË£¬Ò²ËµÃ÷»¹ÊÇÓÐÒ»¼¼Ö®³¤µÄ£¬ÓÐÒ»ÃÅÄܹ»Ñø»î×Ô¼ºµÄÊÖÒÕ¡£Ò²ËãÊÇÊÖÒÕÈË°¡¡£
ͬÊÂÈÃÎÒ°ïÖúÓÅ»¯£¬ÔÚslow query logÀï·¢ÏÖÓÐÁ½¸öSQLÖ´ÐеĴÎÊý×î¶à£¬²¢ÇÒÿ´Î¶¼ÔÚÁ½ÃëÒÔÉÏ¡£ÓÃexplain¿´ÁË£¬Ò²Î´·¢ÏÖË÷ÒýʹÓ÷ ......
×îÏÈÏ£ÍûʹÓÃdatatable.columnsÖÖËùº¬ÓеÄÊôÐÔÖ±½Ó»ñÈ¡Ïà¹ØÐÅÏ¢£¬¿É²âÊÔºó·¢ÏÖ£¬³ýÁË×Ö¶ÎÃûºÍ×Ö¶ÎÀàÐÍ£¬ÆäËûÊý¾ÝÒ»¸ÅÕÒ²»µ½¡£
GOOGLEÍøÉϺܶàÖÖ·½·¨£¬ÆäÖÐ×îÖ±½ÓµÄÊÇÖ±½Ó²éѯSQLSERVERµÄinformation_schema.columsÊÓͼ£¬´ÓÖÐÖ±½Ó»ñÈ¡ÐÅÏ¢£¬²»¹ýºóÀ´ÓÖ·¢ÏÖ£¬ËäÈ»Êý¾ÝʱȫÁË£¬¿ÉÊÇÐèҪͨ¹ýºÜ¸´Ôӵķ½·¨£¨sys.all_columns sys ......