SQL»ù´¡
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:mssql7backupMyNwind_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 sumvalue from table1
ƽ¾ù£ºselect avg(field1) as avgvalue from table1
×î´ó£ºselect max(field1) as maxvalue from table1
×îС£ºselect min(field1) as minvalue from table1
11¡¢ËµÃ÷£º¼¸¸ö¸ß¼¶²éѯÔËËã´Ê
A£º UNION ÔËËã·
Ïà¹ØÎĵµ£º
and exists (select * from sysobjects) //ÅжÏÊÇ·ñÊÇMSSQL
and exists(select * from tableName) //ÅжÏij±íÊÇ·ñ´æÔÚ..tableNameΪ±íÃû
and 1=(select @@VERSION) //MSSQL°æ±¾
And 1=(select db_name()) //µ±Ç°Êý¾Ý¿âÃû
and 1=(select @@servername) //±¾µØ·þÎñÃû
and 1=(select IS_SRVROLEMEMBER('sysadmin')) //Å ......
×÷Õߣº²»Ïê ³ö´¦£ºÍøÂç×ªÔØ 2009/11/18 10:35:22 ÔĶÁ 109 ´Î
¡¡¡¡¼¼Êõˮƽ×ÜÄÜÔÚ³¶Æ¤ºÍ´µÃ«Çó´ÃÖеõ½Ìá¸ß¡£Èç¹û´ÓÀ´²»“Çó´Ã”£¬¿ÉÄܾͲ»»áÖªµÀif(str != "")²»Èçif(str != string.Empty)¸ßЧ¡¢ÅúÁ¿²åÈëºÍɾ³ýµÄsqlÓï¾äÊÇÒªÄÇÑùд²ÅÖ´ÐÐ×î¿ì¡¢½Ó¿ÚºÍ³éÏóÀàµÄÇø±ð²»½öÊÇÓïÑÔ²ãÃæ¡¢ ......
SQL ServerµÄ²¹¶¡°æ±¾¼ì²é²»ÈçWindows ²¹¶¡°æ±¾¼ì²éÖ±½Ó£¬Ò»¸öϵͳ¹ÜÀíÔ±£¬Èç¹û²»Á˽âSQL Server°æ±¾¶ÔÓ¦µÄ²¹¶¡ºÅ£¬¿ÉÄÜÒ²»áÓöµ½Ò»µãÂé·³£¬Òò´ËÔÚÕâ˵Ã÷һϣ¬Í¨¹ýÕâÑùµÄ°ì·¨Åбð»úÆ÷Êǰ²È«µÄ°ì·¨£¬²»»á¶Ôϵͳ²úÉúÈκÎÓ°Ïì¡£
¡¡
1¡¢ÓÃIsql»òÕßSQL²éѯ·ÖÎöÆ÷µÇ¼µ½SQL Server£¬Èç¹ûÊÇÓÃIsql£¬ÇëÔÚcmd´°¿ÚÊäÈëisql -U sa,È» ......
½üÆÚÒò¹¤×÷ÐèÒª£¬Ï£Íû±È½ÏÈ«ÃæµÄ×ܽáÏÂ
SQL SERVER
Êý¾Ý¿âÐÔÄÜÓÅ»¯Ïà¹ØµÄ×¢ÒâÊÂÏÔÚÍøÉÏËÑË÷ÁËÒ»ÏÂ
,
·¢ÏֺܶàÎÄÕÂ
,
ÓеͼÁгöÁËÉϰÙÌõ
,
µ«ÊÇ×Ðϸ¿´·¢ÏÖ£¬ÓкܶàËÆÊǶø·Ç»òÕß¹ýʱ
(
¿ÉÄܶÔ
SQL SERVER6.5
ÒÔǰµÄ°æ±¾»òÕß
ORACLE
ÊÇÊÊÓõÄ
)
µÄÐÅÏ¢£¬Ö»ºÃ×Ô¼º¸ù¾ÝÒÔǰµÄ¾ÑéºÍ²âÊÔ½á¹û½øÐÐ×ܽáÁË¡£
ÎÒ ......
ËäȻ˵ÎÒÃǾ¡Á¿ÔÚд³ÌÐòµÄʱºò¿ØÖƲåÈëµ½Êý¾Ý¿âµÄÊý¾Ý£¬¶ø²»ÒªÓÃÊý¾Ý¿âÈ¥ÅжÏÊý¾ÝµÄ¶Ô´í£¬µ«ÊÇÓÐʱºòΪÁË·½±ã»¹ÊÇÐèÒªÊý¾Ý¿â×ÔÉíµÄÈÝ´íÄÜÁ¦À´°ïÖúÎÒÃǴﵽĿµÄµÄ¡£¾ÙÀý˵Ã÷£º
´´½¨ÈçÏÂÊý¾Ý±í
CREATE TABLE `book` (
`id` int(11) default NULL,
`num` int(11) unsigned default NULL
) ENGINE=InnoDB DE ......