sql操作大全


SQL      2007 11 21      17:35 、      
   Transact-SQL         、FROM   WHERE  。          、   
    、       。
  ,       testtable     “  ” nickname   email  。
SELECT nickname,email
FROM testtable
WHERE name='  '

( )     
    (select_list)      ,          、  、   、  (     
      )   。

1、     
  ,      testtable        :
SELECT *
FROM testtable

2、               
                                。
  :
SELECT nickname,email
FROM testtable

3、     
      ,        。     :
   =  
      
                   ,        ,  ,           
  :
SELECT   =nickname,    =email
FROM testtable

4、     
SELECT     ALL DISTINCT                          ,  
 ALL。  DISTINCT   ,           SELECT             。

5、       
  TOP n [PERCENT]           ,TOP n    n , TOP n PERCENT ,  n 
      ,                 。
  :
SELECT TOP 2 *
FROM testtable
SELECT TOP 20 PERCENT *
FROM testtable

( ) FROM  
FROM    SELECT               。 FROM        256     ,
         。
 FROM             ,            ,             
       。   usertable citytable      cityid ,        cityid  
            :
SELECT username,citytable.cityid
FROM usertable,citytable
WHERE usertable.cityid=citytable.cityid
 FROM                    :
   as   
     
                 :
SELECT username,b.cityid
FROM usertable a,citytable b
WHERE a.cityid=b.cityid
SELECT             ,                        。
  :
SELECT a.au_fname+a.au_lname
FROM authors a,titleauthor ta
(SELECT title_id,title
FROM titles
WHERE ytd_sales>10000
) AS t
WHERE a.au_id=ta.au_id
AND ta.title_id=t.title_id
   , SELECT            t,         。

( )   WHERE        
WHERE        ,          。            20   :
SELECT *
FROM usertable
WHERE age>20
WHERE            :
     (    ):>、>=、=、<、<=、<>、!>、!<
     (            ):BETWEEN…AND…
NOT BETWEEN…AND…
     (               ):IN ( 1, 2……)
NOT IN ( 1, 2……)
     (                 ):LIKE、NOT LIKE
     (         ):IS NULL、NOT IS NULL
     (          ):NOT、AND、OR
1、      :age BETWEEN 10 AND 30   age>=10 AND age<=30
2、      :country IN ('Germany','China')
3、      :       ,                   。   char、
varchar、text、ntext、datetime smalldatetime     。
         :
   %:             ,     ,         %%。
   _:        ,              。
   []:      、      ,               。
[^]:    []   ,                      。
  :
   Publishing  ,  LIKE '%Publishing'
   A  :LIKE '[A]%'
   A   :LIKE '[^A]%'
4、      WHERE age IS NULL
5、     :    NOT、AND、OR
( )       
  ORDER BY                  。ORDER BY        :
ORDER BY {column_name [ASC|DESC]} [,…n]
  ASC    ,    ,DESC   。ORDER BY   ntext、text image       
 。
  :
SELECT *
FROM usertable
ORDER BY age desc,userid ASC
  ,           。

 、     
UNION              SELECT                    ,    
   。UNION      :
select_statement
UNION [ALL] selectstatement
[UNION [ALL] selectstatement][…n]
  selectstatement     SELECT    。
ALL                。      ,                   
 。
     ,                    。  ,               
    。           ,               、        。
   UNION     ,                          ,       
              ,                   。      ,     
 ,                      。
        UNION   ,          ,              。  :
  1 UNION (  2 UNION   3)

 、     
                。               ,          
            。
           ,                ,              
    。      ,                        。        
       ,                 。          ,        
  。
     SELECT    FROM   WHERE     ,     FROM           
      WHERE            。  , Transact-SQL         。
SQL-92      FROM          :
FROM join_table join_type join_table
[ON (join_condition)]
  join_table           ,           ,        ,   
             。
join_type       ,     :   、        。   (INNER JOIN)   
         ( )        ,                   。     
       ,          、           。
         (LEFT OUTER JOIN LEFT JOIN)、    (RIGHT OUTER JOIN RIGHT JOIN)
     (FULL OUTER JOIN FULL JOIN)  。        ,              
   ,      (     )、  (     )    (     )          
   。
    (CROSS JOIN)  WHERE   ,                 ,       
                                        。
      ON (join_condition)         ,               、  
      。
          text、ntext image           ,            
  。  :
SELECT p1.pub_id,p2.pub_id,p1.pr_info
FROM pub_info AS p1 INNER JOIN pub_info AS p2
ON DATALENGTH(p1.pr_info)=DATALENGTH(p2.pr_info)

( )   
                    ,                 。    
  :
1、    :           (=)            ,           
      ,        。
2、    :                                  。  
     >、>=、<=、<、!>、!< <>。
3、    :          (=)            ,            
          ,           。
 ,          authors publishers               :
SELECT *
FROM authors AS a INNER JOIN publishers AS p
ON a.city=p.city
        ,        authors  publishers      (city state):
SELECT a.*,p.pub_id,p.pub_name,p.country
FROM authors AS a INNER JOIN publishers AS p
ON a.city=p.city
( )   
    ,                  ( WHERE       HAVING   )     
  。       ,                        ,       (  
   )、  (     )      (    )       。
                       :
SELECT a.*,b.* FROM luntan LEFT JOIN usertable as b
ON a.username=b.username
         city         user       ,         :
SELECT a.*,b.*
FROM city as a FULL OUTER JOIN user as b
ON a.username=b.username

( )    
      WHERE   ,                    ,          
                                       。
 ,titles   6   , publishers   8    ,                
 6*8=48 。
SELECT type,pub_name
FROM titles CROSS JOIN publishers
ORDER BY typeSQL    (         )     

          ,    SQL INSERT   。                : 

INSERT mytable (mycolumn) VALUES (‘some data’) 

        ’some data’   mytable mycolumn   。                      ,              。 

INSERT          : 

INSERT [INTO] {table_name|view_name} [(column_list)] {DEFAULT VALUES | 

Values_list | select_statement} 

          ,               ,              。   mytable     first_column,second_column, third_column。   INSERT                   : 

INSERT mytable (first_column,second_column,third_column) 

VALUES (‘some data’,’some more data’,’yet more data’) 

   

     INSERT             。  ,             ,     WRITETEXT  。              ,      。        ,   Microsoft SQL Sever    。 

    INSERT                   ?    ,             ,            。      ,        : 

           ,      。  ,              third_column    ,           ’some value’。      ,           ’some value’。 

           ,       ,       。 

           ,       ,      。        : 

The column in table mytable may not be null. 

  ,            ,            。                   ,       ,             。 

   

                 ,    SQL  @@identity       

       。     SQL  : 

INSERT mytable (first_column) VALUES(‘some value’) 

INSERT anothertable(another_first,another_second) 

VALUES(@@identity,’some value’) 

   mytable       ,          anothertable another_first  。      @@identity                。 

  another_first     first_column        。  ,  another_first         。Another_first        first_column  。 

     

             ,    SQL DELETE  。    DELETE     WHERE   。WHERE            。  ,     DELETE       first_column    ’Delete Me’   : 

DELETE mytable WHERE first_column=’Deltet Me’ 

DELETE          : 

DELETE [FROM] {table_name|view_name} [WHERE clause] 

 SQL SELECT                 DELECT    WHERE      。  ,     DELETE       first_column     ’goodbye’ second_column     ’so long’   : 

DELETE mytable WHERE first_column=’goodby’ OR second_column=’so long’ 

     DELETE     WHERE   ,            。         。               ,         TRUNCATE TABLE  。 

   

     TRUNCATE TABLE     DELETE  ?    TRUNCATE TABLE   ,           。    ,    TRUNCATE TABLE   DELETE   。 

     

                 ,   SQL UPDATE  。 DELETE    ,UPDATE      WHERE            。      : 

UPDATE mytable SET first_column=’Updated!’ WHERE second_column=’Update Me!’ 

  UPDATE       second_column     ’Update Me!’   。         ,  first_column     ’Updated!’。 

   UPDATE       : 

UPDATE {table_name|view_name} SET [{table_name|view_name}] 

{column_list|variable_list|variable_and_column_list} 

[,{column_list2|variable_list2|variable_and_column_list2}… 

[,{column_listN|variable_listN|variable_and_column_listN}]] 

[WHERE clause] 

   

           UPDATE  。  ,             ,   UPDATETEXT  。              ,      。        ,   Microsoft SQL Sever    。 

      WHERE  ,            。       。  ,      titles          ,        UPDATE   : 

            。  ,   UPDATE      first_column,second_column, third_column     : 

UPDATE mytable SET first_column=’Updated!’ 

Second_column=’Updated!’ 

Third_column=’Updated!’ 

WHERE first_column=’Update Me1’ 

   

SQL          。    SQL              。 

 SELECT        

        ,INSERT    DELETE   UPDATE       ,          。  ,        INSERT           。      ,    INSERT    SELECT       ,   : 

INSERT mytable (first_column,second_column) 

SELECT another_first,another_second 

FROM anothertable 

WHERE another_first=’Copy Me!’ 

     anothertable     mytable.   anothertable   another_first   ’Copy Me!’       。 

              ,     INSERT         。            ,                    。 

          ,     SELECT INTO   。  ,            newtable   ,     mytable     : 

SELECT * INTO newtable FROM mytable 

                      。      ,                  。  ,     WHERE               。          second_columnd    ’Copy Me!’    first_column  。 

SELECT first_column INTO newtable 

FROM mytable 

WHERE second_column=’Copy Me!’ 

  SQL             。  ,               ,           。  ,                   ,         。  ,        SQL  ,          。 

  ,               。  SELECT INTO   ,            ,          。          ,           。 

               ,                    。      ,        UPDATE   SELECT   ,                。      ,          ,         。 

 
  ,                   …… 

--    
create table Circle 
( 
ID int, 
   varchar(10), 
ID  int 
) 

--     
insert into Circle values (1, 'a', 52) 
insert into Circle values (2, 'a', 53) 
insert into Circle values (3, 'a', 54) 
insert into Circle values (4, 'a', null) 
insert into Circle values (52, 'a', 158) 
insert into Circle values (53, 'a', 159) 
insert into Circle values (54, 'a', null) 
insert into Circle values (158, 'a', 542) 
insert into Circle values (159, 'a', null) 
insert into Circle values (542, 'a', null) 

select * from Circle 

--       
create procedure procCircle @i int 
as 
begin 
declare @sql varchar(max) 
set @sql = 'select * from Circle where ID = ' + convert(varchar, @i) 
while (select ID  from Circle where ID = @i) is not null 
begin 
set @sql = @sql + ' union all ' 
set @i = (select ID  from Circle where ID = @i) 
set @sql = @sql + 'select * from Circle where ID = ' + convert(varchar, @i) 
end 
exec (@sql) 
end 

--           
procCircle 1 
procCircle 2 
procCircle 3 
procCircle 4 

drop procedure procCircle 
SQL    
(1)      : 
sql="select*from   where   =   orderby   [desc]" 
sql="select*from   where   like'%   %'orderby   [desc]" 
sql="selecttop10*from   where   orderby   [desc]" 
sql="select*from   where   in(' 1',' 2',' 3')" 
sql="select*from   where   between 1and 2" 
(2)      : 
sql="update   set   =   where     " 
sql="update   set  1= 1,  2= 2……  n= nwhere     " 
(3)      : 
sql="deletefrom   where     " 
sql="deletefrom   "(          ) 
(4)      : 
sql="insertinto   (  1,  2,  3…)values( 1, 2, 3…)" 
sql="insertinto     select*from    "(                ) 
(5)        : 
AVG(   )           
COUNT(*|   )                       
MAX(   )            
MIN(   )            
SUM(   )         
         : 
sql="selectsum(   )as  from   where     " 
setrs=conn.excute(sql) 
 rs("  ")      ,        。 
(5)         : 
CREATETABLE     (  1  1(  ),  2  2(  )……) 
 :CREATETABLEtab01 (namevarchar (50), datetimedefaultnow ()) 
DROPTABLE     (          ) 
4.        : 
rs.movenext                 
rs.moveprevious                 
rs.movefirst              
rs.movelast               
rs.absoluteposition=N           N  
rs.absolutepage=N        N      
rs.pagesize=N     N    
rs.pagecount  pagesize         
rs.recordcount       
rs.bof               ,true   ,false   
rs.eof               ,true   ,false   
rs.delete      ,            
rs.addnew           
rs.update        




SQL     、  、            ,            ,                     ? 

  、  、    db.Execute(Sql)       
╔----------------╗ 
☆        ☆ 
╚----------------╝ 
  :           (    ) 

Sql = "Select Distinct     From    " 
Distinct  ,               

Sql = "Select Count(*) From     where    1>#18:0:0# and    1< #19:00# " 
count  ,            ,“   1”       
 : 
set rs=conn.execute("select count(id) as idnum from news") 
response.write rs("idnum") 

sql="select * from     where     between  1 and  2" 
Sql="select * from     where     between #2003-8-10# and #2003-8-12#" 
       2003-8-10 19:55:08       2003-8-10 2003-8-12     ,        。 

select * from tb_name where datetime between #2003-8-10# and #2003-8-12# 
          :2003-8-10 19:55:08,  sql  2003-8-10 2003-8-12     ,        。 


Sql="select * from     where    =    order by     [desc]" 

Sql="select * from     where     like '%   %' order by     [desc]" 
     

Sql="select top 10 * from     where     order by     [desc]" 
       10   

Sql="select top n * form     order by newid()" 
                  
top n,n          

Sql="select * from     where     in (' 1',' 2',' 3')" 

╔----------------╗ 
☆        ☆ 
╚----------------╝ 
sql="insert into     (  1,  2,  3 …) valuess ( 1, 2, 3 …)" 

sql="insert into     valuess ( 1, 2, 3 …)" 
                      ,     

sql="insert into       select * from     " 
                 

╔----------------╗ 
☆        ☆ 
╚----------------╝ 
Sql="update     set    =    where      " 

Sql="update     set   1= 1,  2= 2 ……   n= n where      " 

Sql="update     set   1= 1,  2= 2 ……   n= n " 
                    

╔----------------╗ 
☆        ☆ 
╚----------------╝ 
Sql="delete from     where      " 

Sql="delete from    " 
               ) 

╔--------------------╗ 
☆          ☆ 
╚--------------------╝ 
AVG(   )            
COUNT(*|   )                        
MAX(   )             
MIN(   )             
SUM(   )          

         : 
sql="select sum(   ) as    from     where      " 
set rs=conn.excute(sql) 
  rs("  ")       ,        。 

╔----------------------╗ 
☆           ☆ 
╚----------------------╝ 
CREATE TABLE      (  1   1(  ),  2   2(  ) …… ) 
 :CREATE TABLE tab01(name varchar(50),datetime default now()) 
DROP TABLE       (          ) 

╔--------------------╗ 
☆          ☆ 
╚--------------------╝ 
rs.movenext                  
rs.moveprevious                  
rs.movefirst               
rs.movelast                
rs.absoluteposition=N            N  
rs.absolutepage=N         N      
rs.pagesize=N      N    
rs.pagecount    pagesize          
rs.recordcount        
rs.bof                ,true   ,false   
rs.eof                ,true   ,false   
rs.delete       ,            
rs.addnew            
rs.update         
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     。
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
 :        ,          。
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     
UNION               (   TABLE1   TABLE2)                   。  ALL   UNION      (  UNION ALL),      。     ,            TABLE1      TABLE2。 
B: EXCEPT     
EXCEPT            TABLE1      TABLE2                     。  ALL   EXCEPT       (EXCEPT ALL),      。 
C: INTERSECT    
INTERSECT          TABLE1   TABLE2                       。  ALL   INTERSECT       (INTERSECT ALL),      。 
 :                   。 
12、  :      
A、left outer join: 
    (   ):             ,           。 
SQL: select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
B:right outer join: 
    (   ):               ,           。 
C:full outer join: 
    :             ,              。
 、  
1、  :   (     ,   :a    :b) (Access  )
  :select * into b from a where 1<>1
  :select top 0 * into b from a 
2、  :   (    ,   :a     :b) (Access  )
insert into b(a, b, c) select d,e,f from b;
3、  :          (          ) (Access  )
insert into b(a, b, c) select d,e,f from b in ‘     ’ where   
  :..from b in '"&Server.MapPath(".")&"\data.mdb" &"' where..
4、  :   (  1:a   2:b)
select a,b,c from a where a IN (select d from b )   : select a,b,c from a where a IN (1,2,3)
5、  :    、          
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
6、  :     (  1:a   2:b)
select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
7、  :      (  1:a )
select * from (SELECT a,b,c FROM a) T where t.a > 1;
8、  :between   ,between               ,not between   
select * from table1 where time between time1 and time2
select a,b,c, from table1 where a not between   1 and   2
9、  :in      
select * from table1 where a [not] in (‘ 1’,’ 2’,’ 4’,’ 6’)
10、  :     ,                 
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )
11、  :      :
select * from a left inner join b on a.a=b.b right inner join c on a.a=c.c inner join d on a.a=d.d where .....
12、  :            
SQL: select * from      where datediff('minute',f    ,getdate())>5
13、  :  sql          
select top 10 b.* from (select top 20     ,     from    order by      desc) a,   b where b.     = a.     order by a.    
14、  : 10   
select top 10 * form table1 where   
15、  :      b          a          (                  ,        ,       ,  .)
select a,b,c from tablename ta where a=(select max(a) from tablename tb where tb.b=ta.b)
16、  :      TableA      TableB TableC                     
(select a from tableA ) except (select a from tableB) except (select a from tableC)
17、  :    10   
select top 10 * from tablename order by newid()
18、  :      
select newid()
19、  :      
Delete from tablename where id not in (select max(id) from tablename group by col1,col2,...)
20、  :           
select name from sysobjects where type='U' 
21、  :        
select name from syscolumns where id=object_id('TableName')
22、  :  type、vender、pcs  , type    ,case           ,  select   case。
select type,sum(case vender when 'A' then pcs else 0 end),sum(case vender when 'C' then pcs else 0 end),sum(case vender when 'B' then pcs else 0 end) FROM tablename group by type
    :
type vender pcs
   A 1
   A 1
   B 2
   A 2
   B 3
   C 3
23、  :    table1
TRUNCATE TABLE table1
24、  :   10 15   
select top 5 * from (select top 15 * from table order by id asc) table_   order by id desc
 、  
1、1=1,1=2   , SQL         
“where 1=1”           “where 1=2”    ,
 :
if @strWhere !='' 
begin
set @strSQL = 'select count(*) as Total from [' + @tblName + '] where ' + @strWhere 
end
else 
begin
set @strSQL = 'select count(*) as Total from [' + @tblName + ']' 
end 
        
set @strSQL = 'select count(*) as Total from [' + @tblName + '] where 1=1    '+ @strWhere 
2、     
--    
DBCC REINDEX
DBCC INDEXDEFRAG
--       
DBCC SHRINKDB
DBCC SHRINKFILE
3、     
dbcc shrinkdatabase(dbname)
4、                 
exec sp_change_users_login 'update_one','newname','oldname'
go
5、     
RESTORE VERIFYONLY from disk='E:\dvbbs.bak'
6、     
ALTER DATABASE [dvbbs] SET SINGLE_USER
GO
DBCC CHECKDB('dvbbs',repair_allow_data_loss) WITH TABLOCK
GO
ALTER DATABASE [dvbbs] SET MULTI_USER
GO
7、    
SET NOCOUNT ON
DECLARE @LogicalFileName sysname,
        @MaxMinutes INT,
        @NewSize INT

USE     tablename             --         
SELECT  @LogicalFileName = 'tablename_log',  --      
@MaxMinutes = 10,               -- Limit on time allowed to wrap log.
        @NewSize = 1                  --             (M)
-- Setup / initialize
DECLARE @OriginalSize int
SELECT @OriginalSize = size 
  FROM sysfiles
  WHERE name = @LogicalFileName
SELECT 'Original Size of ' + db_name() + ' LOG is ' + 
        CONVERT(VARCHAR(30),@OriginalSize) + ' 8K pages or ' + 
        CONVERT(VARCHAR(30),(@OriginalSize*8/1024)) + 'MB'
  FROM sysfiles
  WHERE name = @LogicalFileName
CREATE TABLE DummyTrans
  (DummyColumn char (8000) not null)

DECLARE @Counter   INT,
        @StartTime DATETIME,
        @TruncLog  VARCHAR(255)
SELECT  @StartTime = GETDATE(),
        @TruncLog = 'BACKUP LOG ' + db_name() + ' WITH TRUNCATE_ONLY'
DBCC SHRINKFILE (@LogicalFileName, @NewSize)
EXEC (@TruncLog)
-- Wrap the log if necessary.
WHILE     @MaxMinutes > DATEDIFF (mi, @StartTime, GETDATE()) -- time has not expired
      AND @OriginalSize = (SELECT size FROM sysfiles WHERE name = @LogicalFileName)  
      AND (@OriginalSize * 8 /1024) > @NewSize  
  BEGIN -- Outer loop.
    SELECT @Counter = 0
    WHILE  ((@Counter < @OriginalSize / 16) AND (@Counter < 50000))
      BEGIN -- update
        INSERT DummyTrans VALUES ('Fill Log')  
        DELETE DummyTrans
        SELECT @Counter = @Counter + 1
      END   
    EXEC (@TruncLog)  
  END   
SELECT 'Final Size of ' + db_name() + ' LOG is ' +
        CONVERT(VARCHAR(30),size) + ' 8K pages or ' + 
        CONVERT(VARCHAR(30),(size*8/1024)) + 'MB'
  FROM sysfiles 
  WHERE name = @LogicalFileName
DROP TABLE DummyTrans
SET NOCOUNT OFF 
8、  :     
exec sp_changeobjectowner 'tablename','dbo'
9、       
CREATE PROCEDURE dbo.User_ChangeObjectOwnerBatch
 @OldOwner as NVARCHAR(128),
 @NewOwner as NVARCHAR(128)
AS
DECLARE @Name   as NVARCHAR(128)
DECLARE @Owner  as NVARCHAR(128)
DECLARE @OwnerName  as NVARCHAR(128)
DECLARE curObject CURSOR FOR 
 select 'Name'   = name,
  'Owner'   = user_name(uid)
 from sysobjects
 where user_name(uid)=@OldOwner
 order by name
OPEN  curObject
FETCH NEXT FROM curObject INTO @Name, @Owner
WHILE(@@FETCH_STATUS=0)
BEGIN     
 if @Owner=@OldOwner 
 begin
  set @OwnerName = @OldOwner + '.' + rtrim(@Name)
  exec sp_changeobjectowner @OwnerName, @NewOwner
 end
-- select @name,@NewOwner,@OldOwner
 FETCH NEXT FROM curObject INTO @Name, @Owner
END
close curObject
deallocate curObject
GO

10、SQL SERVER         
declare @i int
set @i=1
while @i<30
begin
   insert into test (userid) values(@i)
   set @i=@i+1
end 
  ? 
 from
wehere 
    ASP   sql      


(1)      : 
sql="select*from   where   =   orderby   [desc]" 
sql="select*from   where   like'%   %'orderby   [desc]" 
sql="selecttop10*from   where   orderby   [desc]" 
sql="select*from   where   in(' 1',' 2',' 3')" 
sql="select*from   where   between 1and 2" 
(2)      : 
sql="update   set   =   where     " 
sql="update   set  1= 1,  2= 2……  n= nwhere     " 
(3)      : 
sql="deletefrom   where     " 
sql="deletefrom   "(          ) 
(4)      : 
sql="insertinto   (  1,  2,  3…)values( 1, 2, 3…)" 
sql="insertinto     select*from    "(                ) 
(5)        : 
AVG(   )           
COUNT(*|   )                       
MAX(   )            
MIN(   )            
SUM(   )         
         : 
sql="selectsum(   )as  from   where     " 
setrs=conn.excute(sql) 
 rs("  ")      ,        。 
(5)         : 
CREATETABLE     (  1  1(  ),  2  2(  )……) 
 :CREATETABLEtab01 (namevarchar (50), datetimedefaultnow ()) 
DROPTABLE     (          ) 
4.        : 
rs.movenext                 
rs.moveprevious                 
rs.movefirst              
rs.movelast               
rs.absoluteposition=N           N  
rs.absolutepage=N        N      
rs.pagesize=N     N    
rs.pagecount  pagesize         
rs.recordcount       
rs.bof               ,true   ,false   
rs.eof               ,true   ,false   
rs.delete      ,            
rs.addnew           
rs.update        




SQL     、  、            ,            ,                     ? 

  、  、    db.Execute(Sql)       

☆        ☆ 
  :           (    ) 

Sql = "Select Distinct     From    " 
Distinct  ,               

Sql = "Select Count(*) From     where    1>#18:0:0# and    1< #19:00# " 
count  ,            ,“   1”       
 : 
set rs=conn.execute("select count(id) as idnum from news") 
response.write rs("idnum") 

sql="select * from     where     between  1 and  2" 
Sql="select * from     where     between #2003-8-10# and #2003-8-12#" 
       2003-8-10 19:55:08       2003-8-10 2003-8-12     ,        。 

select * from tb_name where datetime between #2003-8-10# and #2003-8-12# 
          :2003-8-10 19:55:08,  sql  2003-8-10 2003-8-12     ,        。 


Sql="select * from     where    =    order by     [desc]" 

Sql="select * from     where     like '%   %' order by     [desc]" 
     

Sql="select top 10 * from     where     order by     [desc]" 
       10   

Sql="select top n * form     order by newid()" 
                  
top n,n          

Sql="select * from     where     in (' 1',' 2',' 3')" 


☆        ☆ 

sql="insert into     (  1,  2,  3 …) valuess ( 1, 2, 3 …)" 

sql="insert into     valuess ( 1, 2, 3 …)" 
                      ,     

sql="insert into       select * from     " 
                 

☆        ☆ 

Sql="update     set    =    where      " 

Sql="update     set   1= 1,  2= 2 ……   n= n where      " 

Sql="update     set   1= 1,  2= 2 ……   n= n " 
                    


☆        ☆ 
Sql="delete from     where      " 

Sql="delete from    " 
               ) 


☆          ☆ 

AVG(   )            
COUNT(*|   )                        
MAX(   )             
MIN(   )             
SUM(   )          

         : 
sql="select sum(   ) as    from     where      " 
set rs=conn.excute(sql) 
  rs("  ")       ,        。 


☆           ☆ 
CREATE TABLE      (  1   1(  ),  2   2(  ) …… ) 
 :CREATE TABLE tab01(name varchar(50),datetime default now()) 
DROP TABLE       (          ) 

╔--------------------╗ 
☆          ☆ 
╚--------------------╝ 
rs.movenext                  
rs.moveprevious                  
rs.movefirst               
rs.movelast                
rs.absoluteposition=N            N  
rs.absolutepage=N         N      
rs.pagesize=N      N    
rs.pagecount    pagesize          
rs.recordcount        
rs.bof                ,true   ,false   
rs.eof                ,true   ,false   
rs.delete       ,            
rs.addnew            
rs.update