sql语句来看看。。

xinleicn 2010-12-29 08:51:21
我想把这些语句改成sql2005的。。。。谁帮帮我啊。。。。
触发器:
(1)确认产品入库:
create trigger reminder1
on 入库表
after insert,update
as
exec msdb.dbo.sp_send_dbmail
@profile_name='库存管理员',
@recipients='sunyitongdlx@163.com',
@body='入库数量发生变化,报告相关部门。',
@subject='已有商品入库'

()确认产品出库:
create trigger reminder2
on 出库表
after insert,update
as
exec msdb.dbo.sp_send_dbmail
@profile_name='库存管理员',
@recipients='sunyitongdlx@163.com',
@body='出库数量发生变化,报告相关部门。',
@subject='已有商品出库'

()设立警戒线,超出警戒线数量则报错:
create trigger 警戒线
on 库存表
after update
AS
DECLARE @num tinyint
select @num = inserted.库存数量 from inserted
IF ( @num > 10000)
BEGIN
RAISERROR ('库存越过警戒线',1,1)
ROLLBACK TRANSACTION
END
添加存储过程
查询图书的入库情况
CREATE PROCEDURE storage
@number varchar(10)
As
select 图书编号,入库数量,入库日期
from 入库表 join 库存表on 入库表.图书编号=库存表.图书编号
where 入库表.图书编号=@number
查询图书的出库情况
CREATE PROCEDURE storage1
@number varchar(10)
As
select 图书编号,出库数量,出库日期
from 出库表 join 库存表on 出库表.图书编号=库存表.图书编号
where 出库表.图书编号=@number


创建数据库的脚本:
/*==============================================================*/
/* DBMS name: Sybase AS Anywhere 9 */
/* Created on: 2010-06-11 11:52:01 */
/*==============================================================*/


if exists(select * from sys.sysforeignkey where role='FK_借条信息表_RELATIONS_库存表') then
alter table 借条信息表
delete foreign key FK_借条信息表_RELATIONS_库存表
end if;

if exists(select * from sys.sysforeignkey where role='FK_入库表_RELATIONS_员工表') then
alter table 入库表
delete foreign key FK_入库表_RELATIONS_员工表
end if;

if exists(select * from sys.sysforeignkey where role='FK_入库表_RELATIONS_库存表') then
alter table 入库表
delete foreign key FK_入库表_RELATIONS_库存表
end if;

if exists(select * from sys.sysforeignkey where role='FK_出库表_RELATIONS_员工表') then
alter table 出库表
delete foreign key FK_出库表_RELATIONS_员工表
end if;

if exists(select * from sys.sysforeignkey where role='FK_出库表_RELATIONS_库存表') then
alter table 出库表
delete foreign key FK_出库表_RELATIONS_库存表
end if;

if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_3_FK'
and t.table_name='借条信息表'
) then
drop index 借条信息表.Relationship_3_FK
end if;

if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_4_FK'
and t.table_name='入库表'
) then
drop index 入库表.Relationship_4_FK
end if;

if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_5_FK'
and t.table_name='入库表'
) then
drop index 入库表.Relationship_5_FK
end if;

if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_2_FK'
and t.table_name='出库表'
) then
drop index 出库表.Relationship_2_FK
end if;

if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='Relationship_6_FK'
and t.table_name='出库表'
) then
drop index 出库表.Relationship_6_FK
end if;

if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='员工表_PK'
and t.table_name='员工表'
) then
drop index 员工表.员工表_PK
end if;

if exists(
select * from sys.sysindex i, sys.systable t
where i.table_id=t.table_id
and i.index_name='库存表_PK'
and t.table_name='库存表'
) then
drop index 库存表.库存表_PK
end if;

if exists(
select * from sys.systable
where table_name='借条信息表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 借条信息表
end if;

if exists(
select * from sys.systable
where table_name='入库表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 入库表
end if;

if exists(
select * from sys.systable
where table_name='出库表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 出库表
end if;

if exists(
select * from sys.systable
where table_name='员工表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 员工表
end if;

if exists(
select * from sys.systable
where table_name='库存表'
and table_type in ('BASE', 'GBL TEMP')
) then
drop table 库存表
end if;

/*==============================================================*/
/* Table: 借条信息表 */
/*==============================================================*/
create table 借条信息表
(
图书编号 varchar(10),
借出图书编号 varchar(10) not null,
借出图书名 varchar(20),
借出人 varchar(20),
借出时间 varchar(10),
借出数量 varchar(10),
还库时间 date,
constraint PK_借条信息表 primary key clustered (借出图书编号)
);

/*==============================================================*/
/* Index: Relationship_3_FK */
/*==============================================================*/
create index Relationship_3_FK on 借条信息表 (
图书编号 ASC
);

/*==============================================================*/
/* Table: 入库表 */
/*==============================================================*/
create table 入库表
(
图书编号 varchar(10),
员工编号 varchar(10),
入库编号 numeric(10) not null,
入库数量 integer
constraint CKC_入库数量_入库表 check (入库数量 is null or (入库数量>0)),
入库日期 date,
Column_6 char(10),
constraint PK_入库表 primary key clustered (入库编号)
);

/*==============================================================*/
/* Index: Relationship_4_FK */
/*==============================================================*/
create index Relationship_4_FK on 入库表 (
员工编号 ASC
);

/*==============================================================*/
/* Index: Relationship_5_FK */
/*==============================================================*/
create index Relationship_5_FK on 入库表 (
图书编号 ASC
);

/*==============================================================*/
/* Table: 出库表 */
/*==============================================================*/
create table 出库表
(
员工编号 varchar(10),
图书编号 varchar(10),
出库编号 numeric(10) not null,
出库数量 integer
constraint CKC_出库数量_出库表 check (出库数量 is null or (出库数量>0)),
出库日期 date,
Column_6 char(10),
constraint PK_出库表 primary key clustered (出库编号)
);

/*==============================================================*/
/* Index: Relationship_2_FK */
/*==============================================================*/
create index Relationship_2_FK on 出库表 (
员工编号 ASC
);

/*==============================================================*/
/* Index: Relationship_6_FK */
/*==============================================================*/
create index Relationship_6_FK on 出库表 (
图书编号 ASC
);

/*==============================================================*/
/* Table: 员工表 */
/*==============================================================*/
create table 员工表
(
员工编号 varchar(10) not null,
员工姓名 varchar(20),
性别 varchar(2),
出生日期 date,
工作日期 date,
联系电话 numeric,
constraint PK_员工表 primary key (员工编号)
);

/*==============================================================*/
/* Index: 员工表_PK */
/*==============================================================*/
create unique index 员工表_PK on 员工表 (
员工编号 ASC
);

/*==============================================================*/
/* Table: 库存表 */
/*==============================================================*/
create table 库存表
(
图书编号 varchar(10) not null,
图书名 varchar(20),
作者 varchar(10),
出版社 varchar(20),
出版日期 date,
价格 varchar(10),
图书类型 varchar(20),
库存数量 integer,
constraint PK_库存表 primary key (图书编号)
);

/*==============================================================*/
/* Index: 库存表_PK */
/*==============================================================*/
create unique index 库存表_PK on 库存表 (
图书编号 ASC
);

alter table 借条信息表
add constraint FK_借条信息表_RELATIONS_库存表 foreign key (图书编号)
references 库存表 (图书编号)
on update restrict
on delete restrict;

alter table 入库表
add constraint FK_入库表_RELATIONS_员工表 foreign key (员工编号)
references 员工表 (员工编号)
on update restrict
on delete restrict;

alter table 入库表
add constraint FK_入库表_RELATIONS_库存表 foreign key (图书编号)
references 库存表 (图书编号)
on update restrict
on delete restrict;

alter table 出库表
add constraint FK_出库表_RELATIONS_员工表 foreign key (员工编号)
references 员工表 (员工编号)
on update restrict
on delete restrict;

alter table 出库表
add constraint FK_出库表_RELATIONS_库存表 foreign key (图书编号)
references 库存表 (图书编号)
on update restrict
on delete restrict;
...全文
232 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2010-12-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 xinleicn 的回复:]
要是能用。。我就不上来了。。。
[/Quote]
sql 2000的代码,在sql 2005里面是可以用的.

如果不能用,建议你给出出错信息.
zipheal 2010-12-30
  • 打赏
  • 举报
回复
就是分项建表,整理一下吗,这有什么难的
999朵玫瑰 2010-12-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dawugui 的回复:]
你这些语句在sql 2005中同样可用.
[/Quote]up
abuying 2010-12-29
  • 打赏
  • 举报
回复

--()设立警戒线,超出警戒线数量则报错:
create trigger 警戒线
on 库存表
after update
AS
DECLARE @num tinyint --tinyint,从 0 到 255 的整型数据。存储大小为 1 字节.太小了,改成int吧
select @num = inserted.库存数量 from inserted
IF ( @num > 10000)--tinyint永远都不可能超过10000
BEGIN
RAISERROR ('库存越过警戒线',1,1)
ROLLBACK TRANSACTION
END




nandy249407850 2010-12-29
  • 打赏
  • 举报
回复
貌似能用啊、如果LZ真不能用那就绑定。。
昵称被占用了 2010-12-29
  • 打赏
  • 举报
回复
帮你做项目?
给RMB吗
wsh236 2010-12-29
  • 打赏
  • 举报
回复
为啥子不能用撒
xinleicn 2010-12-29
  • 打赏
  • 举报
回复
要是能用。。我就不上来了。。。
dawugui 2010-12-29
  • 打赏
  • 举报
回复
你这些语句在sql 2005中同样可用.
飘零一叶 2010-12-29
  • 打赏
  • 举报
回复
楼主想改什么?有什么问题?
AcHerat 元老 2010-12-29
  • 打赏
  • 举报
回复

--额。。。帮顶!
jcx396158820 2010-12-29
  • 打赏
  • 举报
回复
应该可以用的。。。
迷途的书童 2010-12-29
  • 打赏
  • 举报
回复
SQL语句对应SQL2000 和SQL2005 都是通用的!
fengyun142415 2010-12-29
  • 打赏
  • 举报
回复
最起码给个提示
笨熊熊 2010-12-29
  • 打赏
  • 举报
回复

眼花繚亂
出的什麽錯?
叶子 2010-12-29
  • 打赏
  • 举报
回复
应该是向下兼容的呀,不能执行的错误信息是什么?

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧