[sql server][基础] 多表关联创建
来源:互联网 发布:k means java实现 编辑:程序博客网 时间:2024/06/05 16:09
if object_id('tableCD') is not null drop table tableCD---多对多要加个中间表
go
if object_id('tableD') is not null drop table tableD
go
if object_id('tableC') is not null drop table tableC
go
if object_id('tableB') is not null drop table tableB
go
if object_id('tableA') is not null drop table tableA
go
create table tableA (Aid varchar(10) primary key,Aname varchar(20))
insert tableA select 'A1','公司1'
go
create table tableB (Bid varchar(10) primary key,Bname varchar(20),Aid varchar(10) references tableA(Aid) )
insert tableB
select 'B1','部门1','A1' union all
select 'B2','部门2','A1'
go
create table tableC (Cid varchar(10) primary key,Cname varchar(20),Bid varchar(10) references tableB(Bid) )
insert tableC
select 'C1','人员1','B1' union all
select 'C2','人员2','B1' union all
select 'C3','人员3','B2' union all
select 'C4','人员4','B2'
go
create table tableD (Did varchar(10) primary key,Dname varchar(20))
insert tableD
select 'D1','权限1' union all
select 'D2','权限2' union all
select 'D3','权限3' union all
select 'D4','权限4'
go
create table tableCD (CDid int identity primary key,Cid varchar(10) references tableC(Cid)on delete cascade ,Did varchar(10) references tableD(Did)on delete cascade )
insert tableCD
select 'C1','D1' union all
select 'C1','D2' union all
select 'C2','D1' union all
select 'C3','D4'
delete tablec where cid='c1'
--or
--delete tabled where did='d1'
select * from tablecd
/*
(1 行受影响)
(2 行受影响)
(4 行受影响)
(4 行受影响)
(4 行受影响)
(1 行受影响)
CDid Cid Did
----------- ---------- ----------
3 C2 D1
4 C3 D4
(2 行受影响)
*/
- [sql server][基础] 多表关联创建
- SQL server基础之(表间关联)
- sql server UPDATE 多表关联 使用
- SQL Server数据库创建基础
- sql语句创建关联表
- sql基础之表关联
- SQL Server创建表
- sql server创建表
- SQL Server创建表
- MS SQL Server的数据库多表关联更新UPDATE
- MS SQL Server的数据库多表关联更新UPDATE
- SQL Server 2005:ReportingServices 创建(基础)
- SQL Server 基础篇之创建数据库
- 关联表的批量更新(SQL SERVER)
- SQL多表关联
- Sql Server 创建表分区
- sql server 脚本创建表
- Sql server表操作基础
- 最“牛”免费下载遥感影像和DEM的网址大全
- MCS-51 汇编指令集(R开头的指令)
- MCS-51 汇编指令集(S开头的指令)
- Webware.ASP.Ecommerce
- MCS-51 汇编指令集(X开头的指令)
- [sql server][基础] 多表关联创建
- myeclipse7与jad的集成
- GCC/MAKE使用笔记
- POJ 3169 Layout(差分约束系统)
- 电源管理
- Webware_ASP.NET_CMS
- jquery 的dialog 总结
- info level
- oracle新建normal账号时,不能登录的原因是在用户名上加了双引号