前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >新闻发布 sql server代码

新闻发布 sql server代码

作者头像
week
发布2018-08-27 12:55:35
5960
发布2018-08-27 12:55:35
举报
文章被收录于专栏:用户画像用户画像
代码语言:javascript
复制
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 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014年03月20日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档