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

¾«Ãî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:\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 avg(field1) as avgvalue from table1
×î´ó£ºselect max(field1) as maxvalue from table1
×îС£ºselect min(field1) as minvalue from table1
11¡¢ËµÃ÷£º¼


Ïà¹ØÎĵµ£º

SQL Server 2005ÖеÄT SQLÔöÇ¿B

SQL2005ÖÐrow_number( )¡¢rank( )¡¢dense_rank( )¡¢ntile( )º¯ÊýµÄÓ÷¨(2) ÊÕ²Ø
   SQL server 2005ÐÂÔöµÄ¼¸¸öº¯Êý,·Ö±ðÊÇrow_number( )¡¢rank( )¡¢,DENSE_RANK( )¡¢ntile( )ÏÂÃæÒÔʵÀý·Ö±ð¼òµ¥½²½â¡£
1.row_number( )
         ÏÈÀ´µãÊý¾Ý,ÏȽ¨¸ö±í
SET NOCOUNT ......

SQL Server 2005ÖеÄT SQLÔöÇ¿D

µÝ¹éµÄͨÓñí±í´ïʽ
µÝ¹éµÄCTEÊǸù¾ÝÖÁÉÙÁ½¸ö²éѯ£¨»òÕß³ÆÎªÁ½¸ö³ÉÔ±£©¹¹½¨µÄ£¬Ò»¸öÊǷǵݹé²éѯ£¬Ò²³ÉΪ¹Ì¶¨³ÉÔ±£¬Ö»Äܵ÷ÓÃÒ»´Î£¬ÁíÍâÒ»¸öÊǵݹé²éѯ£¬Ò²³ÉΪµÝ¹é³ÉÔ±£¨RM£©£¬¿ÉÒÔ·´¸´µ÷Óã¬Ö±µ½²éѯ²»ÔÙ·µ»ØÐС£²éѯÓÉUNION ALLÔËËã·ûÁ¬½ÓΪһ¸öµ¥¶ÀµÄCTE¡£
--ʹÓõݹéµÄͨÓñí±í´ïʽ
GO
CREATE TABLE CarParts
( ......

PL/SQL È¡µÃɾ³ý¼Í¼µÄÌõÊý

ÔõÑùͳ¼ÆPLSQLÓïÑÔÖÐɾ³ýÓï¾äÖ´ÐÐÖ®ºóÒ»¹²É¾³ýÁ˶àÉÙÌõ¼Í¼¡£
OracleʹÓÃÁ½ÖÖ¹â±ê£ºÏÔʽ¹â±êºÍÒþʽ¹â±ê¡£²»¹ÜÓï¾ä·µ»Ø¶àÉÙÌõ¼Í¼£¬PL/SQLΪʹÓõÄÿһÌõUPDATE¡¢DELETEºÍINSERTµÈSQLÃüÁîÒþʽµÄÉùÃ÷Ò»¸ö¹â±ê¡££¨Òª¹ÜÀíSQLÓï¾äµÄ´¦Àí£¬±ØÐëÒþʽµÄ¸øËü¶¨ÒåÒ»¸ö¹â±ê¡££©
ÔÚPL/SQLÖУ¬µ±Ö´ÐÐDMLÓï¾äµÄʱºò£¬»á×Ô¶¯´ò¿ªÒ»¸öÒþʽ ......

sql server 2008 bcp ÅúÁ¿¸´ÖƳÌÐò ³ö´í ½â¾ö

sql server 2008 bcp ÅúÁ¿¸´ÖƳÌÐò ³ö´í
C:\Documents and Settings>bcp MSPetShop4.dbo.product out c:\1.txt -T
SQLState = 08001, NativeError = -1
Error = [Microsoft][SQL Native Client]SQL ÍøÂç½Ó¿Ú: ¶¨Î»Ö¸¶¨µÄ Server/Instance
ʱ³ö´í [xFFFFFFFF].
SQLState = HYT00, NativeError = 0
Error = [Micros ......

SQL ÐÐÊýµÄÑ¡Ôñ

OracleÊý¾Ý¿â
SELECT
    *
from
(
    SELECT
        ROWNUM AS NO_ROW
        ,row_.*
    from
    (
        SELECT
 &nb ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ