SQL Server 新闻门户网站数据库设计与实现

网友投稿 255 2022-10-22


SQL Server 新闻门户网站数据库设计与实现

create database sc; use sc; create table Admin( adminId int identity(201301,1)primary key, adminName varchar(255) unique not null, pswd varchar(255) not null ); CREATE TABLE Category ( categoryId int identity(1,1) primary key, categoryName varchar(255) unique NOT NULL, counter int DEFAULT 0 ); create table Article( articleId int identity(1,1) primary key, title varchar(255) not null, content ntext , time date not null, categoryId int not null, foreign key (categoryId) references Category(categoryId) on delete no action on update cascade ); /*触发器 添加一条新闻,对应新闻项总数加一*/ create trigger articleInsert on Article for Insert as declare @categoryId int Begin select @categoryId = categoryId from inserted update Category set counter = counter + 1 where categoryId = @categoryId End /*触发器 删除一条新闻,对应新闻项总数减一*/ create trigger articleDelete on Article for delete as declare @categoryId int Begin select @categoryId = categoryId from deleted update Category set counter = counter - 1 where categoryId = @categoryId End


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:springboot整合websocket实现群聊思路代码详解
下一篇:Android alertDialog
相关文章

 发表评论

暂时没有评论,来抢沙发吧~