2023年12月30日发(作者:)

drop table teacher

print '已删除表:teacher'endgo

--**************************************--******************************if exists (select 1

from sysobjects

where id = object_id('book')

and type = 'U')

begin drop table book

print '已删除表:book'endgo

create table [book] ( [id] int not null unique, [name] varchar(50)

)

ALTER TABLE [book] ADD CONSTRAINT PK_gene_book_id PRIMARY KEY(id)

print '已创建:book'go--******************************--******************************if exists (select 1

from sysobjects

where id = object_id('student')

and type = 'U')

begin drop table student

print '已删除表:student'endgo

create table [student] ( [id] int not null unique, [name] varchar(50) not null , [addr] varchar(500) , [birth] datetime , [img] image

)

ALTER TABLE [student] ADD CONSTRAINT PK_gene_student_id PRIMARY KEY(id)

print '已创建:student'go--******************************--******************************create table [studentbook] ( [sid] int not null , [bookid] int not null

[bookid] int not null

)

ALTER TABLE [studentbook] ADD CONSTRAINT PK_gene_studentbook_sid_bookid PRIMARY KEY([sid],[bookid])

--************外键约束*****************ALTER TABLE studentbook ADD CONSTRAINT FK_userbook_userbook FOREIGN KEY(sid) REFERENCES t (id) ON DELETE NO ACTION ON UPDATE NO ACTION--************外键约束*****************--************外键约束*****************ALTER TABLE studentbook ADD CONSTRAINT FK_userbook_userbook1 FOREIGN KEY(bookid) REFERENCES (id) ON DELETE NO ACTION ON UPDATE NO ACTION--************外键约束*****************print '已创建:studentbook'go--******************************--******************************create table [studentinfo] ( [sid] int not null unique, [indate] datetime , [type] int , [desc] varchar(500)

)

ALTER TABLE [studentinfo] ADD CONSTRAINT PK_gene_studentinfo_sid PRIMARY KEY(sid)

--************外键约束*****************ALTER TABLE studentinfo ADD CONSTRAINT FK_studentinfo_student FOREIGN KEY(sid) REFERENCES t (id) ON DELETE NO ACTION

ON UPDATE NO ACTION--************外键约束*****************print '已创建:studentinfo'go--******************************--******************************create table [teacher] ( [id] int not null unique, [name] varchar(50) not null , [bid] int not null

)

ALTER TABLE [teacher] ADD CONSTRAINT PK_gene_teacher_id PRIMARY KEY(id)

--************外键约束*****************ALTER TABLE teacher ADD CONSTRAINT FK_teacher_teacher FOREIGN KEY(bid) REFERENCES (id) ON DELETE NO ACTION ON UPDATE NO ACTION--************外键约束*****************print '已创建:teacher'

using System;using c;namespace { public partial class Book { public Book() { Studentbook = new HashSet(); Teacher = new HashSet(); } public int Id { get; set; } public string Name { get; set; } public virtual ICollection Studentbook { get; set; } public virtual ICollection Teacher { get; set; } }}g System;using c;namespace { public partial class Student { public Student() { Studentbook = new HashSet(); } public int Id { get; set; } public string Name { get; set; } public string Addr { get; set; } public DateTime? Birth { get; set; } public byte[] Img { get; set; } public virtual Studentinfo Studentinfo { get; set; } public virtual ICollection Studentbook { get; set; } }}Teacher:using System;using c;namespace { public partial class Teacher { public int Id { get; set; } public string Name { get; set; } public int Bid { get; set; } public virtual Book B { get; set; } }}

:using System;using c;namespace { public partial class Studentbook { public int Sid { get; set; } public int Bookid { get; set; } public virtual Book Book { get; set; } public virtual Student S { get; set; } }}:using System;using c;namespace { public partial class Studentinfo { public int Sid { get; set; } public DateTime? Indate { get; set; } public int? Type { get; set; } public string Desc { get; set; } public virtual Student S { get; set; } }}:using System;using FrameworkCore;using ta;namespace { public partial class testContext : DbContext { public testContext() { } public testContext(DbContextOptions options) : base(options) { } public virtual DbSet Book { get; set; } public virtual DbSet Student { get; set; } public virtual DbSet Studentbook { get; set; } public virtual DbSet Studentinfo { get; set; } public virtual DbSet Teacher { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!igured) {

{#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See /fwlink/?LinkId=723263 for guidance on storing connection strings. Server("Data Source = .;Initial Catalog = test;User Id = sa;Password = 123456;"); } } protected override void OnModelCreating(ModelBuilder modelBuilder) { otation("ProductVersion", "2.2.6-servicing-10079"); (entity => { e("book"); ex(e => ) .HasName("UQ__book__3213E83ED78FF78C") .IsUnique(); ty(e => ) .HasColumnName("id") .ValueGeneratedNever(); ty(e => ) .HasColumnName("name") .HasMaxLength(50) .IsUnicode(false); }); (entity => { e("student"); ex(e => ) .HasName("UQ__student__3213E83E18FC0D17") .IsUnique(); ty(e => ) .HasColumnName("id") .ValueGeneratedNever(); ty(e => ) .HasColumnName("addr") .HasMaxLength(500) .IsUnicode(false); ty(e => ) .HasColumnName("birth") .HasColumnType("datetime"); ty(e => ) .HasColumnName("img") .HasColumnType("image"); ty(e => ) .IsRequired() .HasColumnName("name") .HasMaxLength(50) .IsUnicode(false); }); (entity => { (e => new { , }) .HasName("PK_gene_studentbook_sid_bookid");

e("studentbook"); ty(e => ).HasColumnName("sid"); ty(e => ).HasColumnName("bookid"); (d => ) .WithMany(p => tbook) .HasForeignKey(d => ) .OnDelete(SetNull) .HasConstraintName("FK_userbook_userbook1"); (d => d.S) .WithMany(p => tbook) .HasForeignKey(d => ) .OnDelete(SetNull) .HasConstraintName("FK_userbook_userbook"); }); (entity => { (e => ) .HasName("PK_gene_studentinfo_sid"); e("studentinfo"); ex(e => ) .HasName("UQ__studenti__DDDFDD370E427379") .IsUnique(); ty(e => ) .HasColumnName("sid") .ValueGeneratedNever(); ty(e => ) .HasColumnName("desc") .HasMaxLength(500) .IsUnicode(false); ty(e => ) .HasColumnName("indate") .HasColumnType("datetime"); ty(e => ).HasColumnName("type"); (d => d.S) .WithOne(p => tinfo) .HasForeignKey(d => ) .OnDelete(SetNull) .HasConstraintName("FK_studentinfo_student"); }); (entity => { e("teacher"); ex(e => ) .HasName("UQ__teacher__3213E83EAD9D5139") .IsUnique(); ty(e => ) .HasColumnName("id") .ValueGeneratedNever(); ty(e => ).HasColumnName("bid");