一次插入多条信息(sql)
注释:只适合单表单列数据,
create database test
go
use test
go
create table users
(
:id int identity(1,1) primary key not null,
:name nvarchar(20)
)
go
create proc sp_Inserts
@Names nvarchar(4000)
as
declare @Name nvarchar(20),@ErrorSum int
:set @ErrorSum = 0
:begin tran
:while(len(@Names)>0)
:begin
::if(charindex(',',@Names)<>len(@Names))
::begin
:::set @Name = substring(@Names,0,charindex(',',@Names))
:::insert into users(name) values(@Name)
:::set @ErrorSum = @ErrorSum + @@error
:::set @Names = substring(@Names,(charindex(',',@Names)+1),(len(@Names)-(charindex(',',@Names))))
::end
::else
::begin
:::set @Name = substring(@Names,0,charindex(',',@Names))
:::insert into users(name) values(@Name)
:::set @ErrorSum = @ErrorSum + @@error
:::set @Names = ''
::end
:end:
:if(@ErrorSum<>0)
::rollback tran
:else
::commit tran
go
sp_Inserts 'Tom,Jack,Bob,'
相关文档:
在2005中有同义词与复制的概念
同义词的主要作用是:
一:宿短对象的名称,减少工作人员书写的时间,提高效率。我们知道访问数据库一个对象的通常最全的对象名称是:服务器名称。数据库名称。架构名称。对象名称
二:同步数据。 ......
PL/SQL实例分析
第五章
1、PL/SQL实例分析
1)在【SQLPlus Worksheet】中直接执行如下SQL代码完成上述操作。(创建表)
―――――――――――――――――――――――――――――――
CREATE TABLE "SCOTT"."TESTTABLE" ("RECORDNUMBER" NUMBER(4) NOT NULL, "CURRENTDATE" DATE NOT NULL)
TABLESPACE "SYSTEM ......
drop table father;
create table father(
id int identity(1,1) primary key,
name varchar(20) not null,
age int not null
)
drop table mother;
create table mother(
id int identity(1,1),
name varchar(20) not null,
age int not null,
husban ......
一个简单的例子:
先建一个C#类:
引用System.Data.Linq.dll程序集,
using System.Data.Linq.Mapping和
using System.Data.Linq 两个空间。
[Table]
public class Inventory
{
[Column]
public string Make;
[Column]
public string Color;
&nbs ......
在Visual Studio 2008 中使用O/R设计器:
点添加项目,选择创建Linq to SQL项目,使用服务器资源管理器连接Northwind数据库,将Customers和Orders两个表拖到设计界面上,系统会自动创建app.config和Northwid.designer.cs,前者是配置连接数据库的连接字串;后者会生成一个继承自DataContext的类:NorthwindDataContext。
......