用户定义函数不能用于执行一组修改全局数据库状态的操作,只能对函数内的临时表进行INSERT,DELETE和UPDATE操作垃圾数据库,什么破规定啊
解决方案 »
- 如何在sqlserver中查询两个表
- 求SQL语句
- 一个关于集合交的问题
- 根据条件排序
- 把SQL 数据库直接复制到客户端,而客户端没装SQL server 在程序里还能读取数据库么?
- 如果某个字段是密码,你们如何处理的,难道也就这样以字符形式存放?
- SQL7.0中怎么将一个机器的上的数据库文件拿到另一个机器,并将其转换成数据库?在线等你解答,不够还可以加分
- 新手上路———不知删除非空文件怎么操作?3Q~~
- 有谁知道SQL Server6.5下那条系统stored procdure 可以修改数据库的语言设置?
- 创建存储过程中 数据记录疯狂增长
- 怎样在MS SQL 2000中设置 区分表名大小写?
- 怎样让sqlserver的cpu占用率提高到100%
create table IntKey(KeyChar char(10))
go
create function GetKey()
returns char(10)
as
begin
declare @KeyValue int
declare @KeyReturn varchar(20)
set @KeyValue = cast(isnull((select max(KeyChar) from IntKey),0) as int) + 1
set @KeyReturn = '000000000' + ltrim(str(@KeyValue))
return right(@KeyReturn,10)
endgodeclare @i int
set @i = 0
while @i < 100
begin
insert into IntKey(KeyChar)
select dbo.GetKey()
set @i = @i + 1
end
select * from IntKey
go
drop function GetKey
drop table IntKey
然后主键数值是自增的
create table IntKey(KeyChar char(10),字段 nvarchar(20))
insert into IntKey(KeyChar,字段)
select dbo.GetKey(),'字段值'
这样KeyChar就是自增的了
更重要的是每个表都要单独处理了