主从表的创建,查询代码待增加

来源:互联网 发布:windows微信是什么 编辑:程序博客网 时间:2024/06/04 01:40
/*建立主从表时,应先建立从表,后建立主表。删除时,先删除主表,后删除从表。向表中添加数据时,先添加从表中的数据,后添加主表中的数据。*/
create table data
(
    s_id int primary key identity,/*外键1*/
    
    d_id int not null,
    d_val int,
)

create table senser
(
    e_id int primary key,/*外键2*/

    s_name nvarchar(20) not null,
    s_unit nvarchar(20) not null,    
    s_id int foreign key references data(s_id) not null,/*外键1*/
)

create table equipment
(
    id int primary key identity,/*非空*/
    
    e_id int foreign key references senser(e_id) not null,/*外键2*/
    e_name nvarchar(20) not null,
)

drop table equipment;
drop table senser;
drop table data;

/*查询数据*/
0 0
原创粉丝点击