易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : sqlserver

ASP中使用SQLServer的事务控制及批执行Sql语句

<%
   SQL1 = "update table1 set a=b where id=1"
   Conn.ExeCute SQL1
    SQL2 = "update table2 set a=b where id=2"
   Conn.ExeCute SQL2
   SQL3 = "update table3 set a=b where id=3"
   Conn.ExeCute SQL3
%>
    事实上,这是一种效率很低下的写法,为了提高SQL的执行效率,我们可以把多个SQL语句用分号拼接在一起,然后一次性交给Conn来执行。如下:
<%   
    SQL1 = "update table1 set a=b where id=1"
    SQL2 = "update table2 set a=b where id=2"
    SQL3 = "update table3 set a=b where id=3"
    SQL = SQL1 & ";" & SQL2 & ";" & SQL3
    Conn.ExeCute SQL
%>
    但是,以上2种写法都会面临一个问题,就是当我们需要保证3条SQL语句都必须完整执行,当某一条执行错误时,其他2条也跟着回滚时,我们就需要用到SQLServer的事务控制了,不少的文章建议使用以下方法:
<%
dim Conn=Server.CreateObj ......

ASP中使用SQLServer的事务控制及批执行Sql语句

<%
   SQL1 = "update table1 set a=b where id=1"
   Conn.ExeCute SQL1
    SQL2 = "update table2 set a=b where id=2"
   Conn.ExeCute SQL2
   SQL3 = "update table3 set a=b where id=3"
   Conn.ExeCute SQL3
%>
    事实上,这是一种效率很低下的写法,为了提高SQL的执行效率,我们可以把多个SQL语句用分号拼接在一起,然后一次性交给Conn来执行。如下:
<%   
    SQL1 = "update table1 set a=b where id=1"
    SQL2 = "update table2 set a=b where id=2"
    SQL3 = "update table3 set a=b where id=3"
    SQL = SQL1 & ";" & SQL2 & ";" & SQL3
    Conn.ExeCute SQL
%>
    但是,以上2种写法都会面临一个问题,就是当我们需要保证3条SQL语句都必须完整执行,当某一条执行错误时,其他2条也跟着回滚时,我们就需要用到SQLServer的事务控制了,不少的文章建议使用以下方法:
<%
dim Conn=Server.CreateObj ......

ASP中使用SQLServer的事务控制及批执行Sql语句

<%
   SQL1 = "update table1 set a=b where id=1"
   Conn.ExeCute SQL1
    SQL2 = "update table2 set a=b where id=2"
   Conn.ExeCute SQL2
   SQL3 = "update table3 set a=b where id=3"
   Conn.ExeCute SQL3
%>
    事实上,这是一种效率很低下的写法,为了提高SQL的执行效率,我们可以把多个SQL语句用分号拼接在一起,然后一次性交给Conn来执行。如下:
<%   
    SQL1 = "update table1 set a=b where id=1"
    SQL2 = "update table2 set a=b where id=2"
    SQL3 = "update table3 set a=b where id=3"
    SQL = SQL1 & ";" & SQL2 & ";" & SQL3
    Conn.ExeCute SQL
%>
    但是,以上2种写法都会面临一个问题,就是当我们需要保证3条SQL语句都必须完整执行,当某一条执行错误时,其他2条也跟着回滚时,我们就需要用到SQLServer的事务控制了,不少的文章建议使用以下方法:
<%
dim Conn=Server.CreateObj ......

sqlserver 存储过程

create database db
use db
create table sampleTable
(
 fId int identity(1,1)  primary key,
 fName varchar(10),
 fGrade int,
)
select * from sampleTable
insert into sampleTable values ('张柏',69);
insert into sampleTable values ('李玉梅',100);
insert into sampleTable values ('李四',100);
--普通存储过程
create proc queryInfo
as
  select * from sampleTable
go
drop proc queryInfo
exec queryInfo
--传入参数--
create proc idIn
@id int
as
  select * from sampleTable where fid =@id
go
drop proc idIn
exec idIn 1
--传入参数--
create proc nameIn
@name varchar(10)
as
  select * from sampleTable where fname =@name
go
exec nameIn '张柏'
--传入、传出参数--
create proc nameOut
@id int,
@name varchar(10) output
as
begin
  select @name=fname from sampleTable where fid =@id
end
drop proc nameOut
declare @name varchar(10)
exec nameOut 1,@name output
select @name
--带通配符的参数
create proc qwnbcOut
@name varchar(10) =' ......

sqlserver常用函数/存储过程/数据库角色

/*日期函数*/
DATEADD ( datepart , number, date )
--在向指定日期加上一段时间的基础上,返回新的 datetime 值。
DATEDIFF ( datepart , startdate , enddate )
--返回跨两个指定日期的日期和时间边界数。
DATENAME ( datepart , date )
--返回代表指定日期的指定日期部分的字符串。
DATEPART ( datepart , date )
--返回代表指定日期的指定日期部分的整数。
DAY ( date )
--返回代表指定日期的天的日期部分的整数。
GETDATE ( )
--按 datetime 值的 Microsoft? SQL Server? 标准内部格式返回当前系统日期和时间。
GETUTCDATE()
--返回表示当前 UTC 时间(世界时间坐标或格林尼治标准时间)的 datetime 值。
--当前的 UTC 时间得自当前的本地时间和运行 SQL Server 的计算机操作系统中的时区设置。
MONTH ( date )
--返回代表指定日期月份的整数。
YEAR ( date )
--返回表示指定日期中的年份的整数。
--------------------------------------------------------------------------
/*字符串处理函数*/
LCASE( )
LOWER( )
--将字符串转换为小写字母
LTRIM( )
--删除字符串前面的空格
SUBSTRING( )
--从字符串中提取一个或多个字符
UC ......

SQLSERVER 存储过程 语法

SQLSERVER存儲過程的寫法格式規格
*****************************************************
*** author:Susan
*** date:2005/08/05
*** expliation:如何寫存儲過程的格式及例子,有游標的用法!
*** 本版:SQL SERVER 版!
******************************************************/
在存儲過程中的格式規格:
CREATE PROCEDURE XXX
/*
列舉傳入參數
1:名稱,2:類型,包括長度
Eg:@strUNIT_CODE varCHAR(3)
*/
參數1,
參數2……………
As
/*
定義內部參數
1:名稱,2:類型,包括長度
Eg:@strUNIT_CODE varCHAR(3)
*/
Declare
參數1,
參數2……………
/*
初始化內部參數
Eg:SET @strUNIT_CODE=’’
*/
Set參數1的初始值
Set參數2的初始值…………
/*
過程的主內容&# ......

SQLSERVER 分页存储过程(2 在SQL2005下使用)

之前有一个SQLServer的分页存储过程 但是性能不是十分理想
又找了一个 
--SQL2005分页存储过程
/**
if  exists(select * from sysobjects where name='fenye')
drop proc fenye
**/
CREATE procedure fenye
  @tableName nvarchar(200) ,
  @pageSize int,
  @curPage int ,
  @orderBy nvarchar(200) ,
  @field nvarchar(200) = '*' ,
  @condition nvarchar(200)
AS
  SET NOCOUNT ON
  DECLARE
     @STMT nvarchar(max),        -- SQL to execute
     @recct int                  -- total # of records (for GridView paging interface)
  IF LTRIM(RTRIM(@condition)) = '' SET @condition = '1 = 1'
  IF @pageSize IS NULL BEGIN
    SET @STMT =  'SELECT   ' + @field + 'from ' + @tableName +'WHERE    ' + @condition + 'ORDER BY   ' + ......

SQLSERVER 分页存储过程(2 在SQL2005下使用)

之前有一个SQLServer的分页存储过程 但是性能不是十分理想
又找了一个 
--SQL2005分页存储过程
/**
if  exists(select * from sysobjects where name='fenye')
drop proc fenye
**/
CREATE procedure fenye
  @tableName nvarchar(200) ,
  @pageSize int,
  @curPage int ,
  @orderBy nvarchar(200) ,
  @field nvarchar(200) = '*' ,
  @condition nvarchar(200)
AS
  SET NOCOUNT ON
  DECLARE
     @STMT nvarchar(max),        -- SQL to execute
     @recct int                  -- total # of records (for GridView paging interface)
  IF LTRIM(RTRIM(@condition)) = '' SET @condition = '1 = 1'
  IF @pageSize IS NULL BEGIN
    SET @STMT =  'SELECT   ' + @field + 'from ' + @tableName +'WHERE    ' + @condition + 'ORDER BY   ' + ......

SQLserver中用convert函数转换日期格式

select getdate()
结果:2003-12-28 16:52:00.107
select convert(char(8),getdate(),112)
结果:20031228
select convert(char(8),getdate(),108)
结果:16:52:00
select convert(char(8),getdate(),112)
                                  |
                            指日期格式
规则如下:
1 101 美国 mm/dd/yyyy
2 102 ANSI yy.mm.dd
3 103 英国/法国 dd/mm/yy
4 104 德国 dd.mm.yy
5 105 意大利 dd-mm-yy
6 106 - dd mon yy
7 107 - mon dd, yy
8 108 - hh:mm:ss
- 9 或 109 (*)  默认值 + 毫秒 mon dd yyyy hh:mi:ss:mmmAM(或 PM)
10 110 美国 mm-dd-yy
11 111 日本 yy/mm/dd
12 112 ISO yymmdd
- 13 或 113 (*)  欧洲默认值 + 毫秒 dd mon yyyy hh:mm:ss:mmm(24h)
14 114 - hh:mi:ss:mmm( ......
总记录数:341; 总页数:57; 每页6 条; 首页 上一页 [45] [46] [47] [48] 49 [50] [51] [52] [53] [54]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号