第十二章项目案例:QQ数据库管理

本文通过创建QQUser、BaseInfo和Relation表,详细展示了如何管理QQ数据库,包括用户信息、好友关系及状态。通过ALTER TABLE添加外键约束,确保数据一致性。然后插入、查询、更新和删除数据,实现用户信息的完整操作流程,如好友查询、在线状态筛选、黑名单管理等。
摘要由CSDN通过智能技术生成

创建表结构。并且添加约束。

create table QQUser(
QQID bigint primary key,
PassWord varchar(50) check(len(PassWord)>=6) not null,
LastLogTime datetime not null,
Online int check(Online=‘1’ or Online=‘2’ or Online=‘0’),
Level int default(0)
)
go
create table BaseLnfo(
ID int identity(1,1) primary key,
QQID bigint not null,
NickName varchar(50) not null,
Sex int check(Sex=1 or Sex=0) not null,
Age int check(Age>0 and Age<100) not null,
Province varchar(50) not null,
City varchar(50) not null,
Address varchar(50) not null,
Phone char(30) not null
)
go
create table Relation(
QQID bigint not null,
RelationQQID bigint not null,
RelationStatus int check(RelationStatus=0 or RelationStatus=1) not null
)
go

建立关系。

alter table Relation
add constraint Fk_rel_use foreign key(QQID) references QQUser(QQID);
go
alter table Relation
add constraint Fk_rel_user foreign key(RelationQQID) references QQUser(QQID);
go
alter table Baselnfo
add constraint Fk_bas_use foreign key(QQID) references QQUser(QQID);
go

插入数据。

insert QQUser
(QQID,PassWord,LastLogTime,Online,Level)
select ‘54789625’,‘add512#&’,‘2013-2-16 17:01:35’,‘2’,‘1’ uni

  • 4
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值