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
SQL Server 新闻门户网站数据库设计与实现
原创
©著作权归作者所有:来自51CTO博客作者姜兴琪的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:mysql 权限
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
SQL Server 账号管理1
SQL Server 账号管理主要包含登录名、用户、架构、角色等管理。通过对账号的管理可以有效的提高数据库系统的安全性,规范运维及使用。注意:登录名是实例下的安全对象,用户、架构及角色是数据库下的安全对象
登录名 用户名 数据库级的主体 SQL Server 级的主体 安全对象 -
在循环中创建网页元素的问题
在循环中创建网页元素的问题
Query 循环