¾µäSQLÓï¾ä´óÈ«(ÊʺÏSQL SERVER)
ÏÂÁÐÓï¾ä²¿·ÖÊÇ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 sumvalue from table1
¡
Ïà¹ØÎĵµ£º
select batch_no "Åú´ÎºÅ",get_id "·ÖÀà" from (
select(
select plan1.batch_no from product_plan plan1 where plan1.item_no=(select head1.product_code from wo_head head1 where head1.order_no =bbb)) batch_no,
(select decode(get_id,'BUY','Í⹺¼þ','MAK','×ÔÖÆ¼þ','MB','䶨') from item where item_ ......
Çë°´²½Öè½øÐУ¬Î´½øÐÐÇ°ÃæµÄ²½Öèʱ£¬Çë²»Òª×öºóÃæµÄ²½Ö裬ÒÔÃâËð»µÄãµÄÊý¾Ý¿â¡£
Ò»°ã²»½¨Òé×öµÚ4£¬6Á½²½£¬µÚ4²½²»°²È«£¬ÓпÉÄÜËð»µÊý¾Ý¿â»ò¶ªÊ§Êý¾Ý¡£µÚ6²½Èç¹ûÈÕÖ¾´ïµ½ÉÏÏÞ£¬ÔòÒÔºóµÄÊý¾Ý¿â´¦Àí»áʧ°Ü£¬ÔÚÇåÀíÈÕÖ¾ºó²ÅÄָܻ´¡£
1¡¢Çå¿ÕÈÕÖ¾
DUMP TRANSACTION ¿âÃû WITH NO_LOG
2¡¢½Ø¶ÏÊÂÎñÈÕÖ¾
B ......
Ò»¡¢µ¥±í²éѯÁ·Ï°
1¡¢²éѯ<ѧÉúÐÅÏ¢±í>£¬²éѯѧÉú"ÕÅÈý"µÄÈ«²¿»ù±¾ÐÅÏ¢
Select *
from A_studentinfo
where sname='ÕÅÈý'
2¡¢²éѯ<ѧÉúÐÅÏ¢±í>£¬²éѯѧÉú"ÕÅÈý"ºÍ”ÀîËÄ”µÄ»ù±¾ÐÅÏ¢
Select *
from A_studentinfo
where sname='ÕÅÈý'
or sname='ÀîËÄ'
3¡¢²éѯ<ѧÉú ......
SQL ServerÁ¬½ÓÔ¶³ÌÊý¾ÝÔ´µÄ»ù±¾·½·¨ÓÐÏÂÃæÈýÖÖ£º
OPENDATASOURCE: The OPENDATASOURCE function is used to specify connection information for a remote data source by specifying the OLE DB provider and an initialization string. OPENDATASOURCE can be used directly within a SELECT, INSERT, UPDATE, or DELET ......
Sql Server ÖÐÒ»¸ö·Ç³£Ç¿´óµÄÈÕÆÚ¸ñʽ»¯º¯Êý
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06
Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3): 16/05/06
Select CONVERT(varchar(100), GE ......