我从课程表中引用了学生表中的Coursename

发布于 2025-02-12 17:44:10 字数 386 浏览 0 评论 0原文

我创建了一个课程表,其中CID作为INT是主要键,并且是Varchar的课程 和第二个表格学生,其中varchar并从CID列中的课程表中获取参考

CREATE TABLE Course (
    cID int NOT NULL IDENTITY(1,1) PRIMARY KEY, 
    course varchar(10)
)


CREATE TABLE Student(
    ID int NOT NULL IDENTITY(1001,1) PRIMARY KEY ,
    StudentName varchar(10), 
    RollNo int,
    course  varchar(10) FOREIGN KEY REFERENCES Course(cID), 
);

I create a course table where cId as INT is primary key and course as VARCHAR
and second table student where course is varchar and am taking reference from course table in cId column

CREATE TABLE Course (
    cID int NOT NULL IDENTITY(1,1) PRIMARY KEY, 
    course varchar(10)
)


CREATE TABLE Student(
    ID int NOT NULL IDENTITY(1001,1) PRIMARY KEY ,
    StudentName varchar(10), 
    RollNo int,
    course  varchar(10) FOREIGN KEY REFERENCES Course(cID), 
);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一萌ing 2025-02-19 17:44:10
create table #course(cid int identity(1,1)primary key,
course varchar(20))

insert into #course values('science'),('eng'),('maths'),('biology')
cid  course
1   science
2   eng
3   maths
4   biology

create table #student(id int identity(1001,1)primary key,
studentName varchar(30), RollNO int,
courseid int foreign key references #course(cid))

请参阅课程名称我的课程ID,数据将以归一化形式

insert into #student values('john',101,1),('ker',102,3),('ghm',103,2),  ('ahm',104,3)
id     studentname   rollno courseid
1001    john            101     1
1002    ker             102     3
1003    ghm             103     2
1004    ahm             104     3
create table #course(cid int identity(1,1)primary key,
course varchar(20))

insert into #course values('science'),('eng'),('maths'),('biology')
cid  course
1   science
2   eng
3   maths
4   biology

create table #student(id int identity(1001,1)primary key,
studentName varchar(30), RollNO int,
courseid int foreign key references #course(cid))

Refer the course name my courseid , data will be in normalize form

insert into #student values('john',101,1),('ker',102,3),('ghm',103,2),  ('ahm',104,3)
id     studentname   rollno courseid
1001    john            101     1
1002    ker             102     3
1003    ghm             103     2
1004    ahm             104     3
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文