[懒人合集]网站通用程序集 2 【转】

本文提供了一组针对 SQL Server 的通用存储过程,包括查询、插入、更新和删除操作。这些存储过程支持参数化查询,提高了数据库操作的灵活性和安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

SQLSERVER 通用存储过程

 

ContractedBlock.gif ExpandedBlockStart.gif Code
/*******create by liqiang665@163.com**********/

/*******通用SQL操作:查找,增加,更新,删除 存储过程******/

/*******2008-07-10***********************/

/*
--说明
--创建数据库
create database mydatabase
on
(
name='xx',
filename='d:/mydb/xx.mdf'
)
log on
(
name='xxlog',
filename='d:/mydb/xxlog.ldf'
)
go
use
mydatabase
go
--然后创建表
create table mytable()
go
再加入以下存储过程即可
*/
--查询过程 select filter from tablename where condition order by sort
if object_id('lq_select_all_table'is not null
drop proc lq_select_all_table
go

create proc lq_select_all_table
@filter varchar(4000)='*'
@tablename varchar(255),
@condition varchar(1000)=''
@sort varchar(255)='' 
as
if @filter is null or @filter=''
set @filter='*'
if @condition is not null and @condition<>''
set @condition=' where '+@condition
if @sort is not null and @sort<>''
set @sort=' order by '+@sort

set xact_abort on
begin tran lq_select
exec(' select '+@filter+' from '+@tablename+' '+@condition+' '+@sort)
commit tran lq_select
if @@error<>0 rollback tran lq_select


go


--插入操作 insert into values/selct,插入成功后返回最后的ID号 
if object_id('lq_insert_all_table'is not null
drop proc lq_insert_all_table
go

create proc lq_insert_all_table
@tablename varchar(255),
@filter varchar(1000),
@values text,
@primarykeyid int out,
@selecttype bit=0
as
set xact_abort on
begin tran lq_insert
if @filter is null or @filter=''
    
if @selecttype=0
    
exec(' insert into '+@tablename+' '+'values( '''+@values+''' )')
    
else
    
exec(' insert into '+@tablename+' '+@values)
else 
    
if @selecttype=0
    
exec(' insert into '+@tablename+'('+@filter+')' + 'values ('''+@values+''' )')
    
else
    
exec(' insert into '+@tablename+'('+@filter+')' + ' '+@values)
if @@rowcount>0
set @primarykeyid=@@IDENTITY
commit tran lq_insert
if @@error<>0 rollback tran lq_insert


go


--更新操作 update table1 set aa=bb from table2 where condition
if object_id('lq_update_all_table'is not null
drop proc lq_update_all_table
go

create proc lq_update_all_table
@tablename1 varchar(255),
@filterandvalues text,
@tablename2 varchar(255)='',
@condition varchar(1000)=''
as
if @condition is not null and @condition<>''
set @condition=' where '+@condition
set xact_abort on
begin tran lq_update
if @tablename2 is null or @tablename2=''
exec (' update '+@tablename1+' set '+@filterandvalues+' '+@condition)
else
exec (' update '+@tablename1+' set '+@filterandvalues+' from '+@tablename2+' '+@condition)
commit tran lq_update
if @@error>0 rollback tran lq_update


go


--删除 delete from table where condition
if object_id('lq_delete_all_table'is not null
drop proc lq_delete_all_table
go

create proc lq_delete_all_table
@tablename varchar(255),
@condition varchar(1000)=''
as
if @condition is not null and @condition<>''
set @condition=' where '+@condition
set xact_abort on
begin tran lq_delete
exec(' delete from '+@tablename+' '+@condition)
commit tran lq_delete
if @@error>0 rollback tran lq_delete


go

 

使用程序集的方法.因为是涉及到SQLSERVER,Access,mysql.所以要在web.config里写上连接字符串,如:

<configuration>
  <appSettings>
    <add key="author" value="liqiang665,liqiang665@163.com,http://www.sz3w.cn,QQ:16826375"/>
    <add key="OLEConnectionString" value="Provider=Microsoft.jet.OleDB.4.0;data Source="/>
    <add key="dbPath" value="~/Database/$$$MainDatabaseContent-----lq.aspx"/>
    <add key="MySqlConnectionString" value="server='localhost';database='mydb';uid='root';pwd=''"/>
    <add key="FCKeditor:BasePath" value="~/FCKeditor/"/>
    <add key="FCKeditor:UserFilesPath" value="/FCKUpFilesTemp/"/>
  </appSettings>
  <connectionStrings>
    <add name="SQLConnectionString" connectionString="server=;database;uid=;pwd="/>
  </connectionStrings>

 

同时需要把bin目录下的相关动态链接库拷贝到相应的网站bin目录下面并引用.

其它的就懒得说了.

 

程序集可以从这里下载LQWebCmd程序集下载

转载于:https://www.cnblogs.com/JemBai/archive/2008/09/08/1287035.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值