Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
这几张表在mysql里和oracle里怎么建表的啊 ,主要是外键怎么关联的啊 都忘了这些
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
这几张表在mysql里和oracle里怎么建表的啊 ,主要是外键怎么关联的啊 都忘了这些
另外建议不要用C#这样的列名,因为带#的一般用来做临时表drop table if exists Course;drop table if exists Student;drop table if exists Table_4;drop table if exists teacher;/*==============================================================*/
/* Table: Course */
/*==============================================================*/
create table Course
(
stu int not null,
cname varchar(20) not null,
tid int not null,
stuid int,
primary key ()
);/*==============================================================*/
/* Table: Student */
/*==============================================================*/
create table Student
(
stuid int not null,
stuname varchar(20) not null,
stuage int not null,
stusex int not null,
primary key (stuid)
);/*==============================================================*/
/* Table: Table_4 */
/*==============================================================*/
create table Table_4
(
sid int not null,
score double not null,
primary key (sid)
);/*==============================================================*/
/* Table: teacher */
/*==============================================================*/
create table teacher
(
tid int not null,
tname varchar(20) not null,
primary key (tid)
);alter table Course add constraint FK_Reference_1 foreign key (tid)
references teacher (tid) on delete restrict on update restrict;alter table Course add constraint FK_Reference_3 foreign key (stuid)
references Student (stuid) on delete restrict on update restrict;alter table Table_4 add constraint FK_Reference_2 foreign key ()
references Course on delete restrict on update restrict;
/*==============================================================*/
/* DBMS name: Microsoft SQL Server 2000 */
/* Created on: 2010-5-31 11:16:28 */
/*==============================================================*/
if exists (select 1
from dbo.sysreferences r join dbo.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('Course') and o.name = 'FK_COURSE_REFERENCE_TEACHER')
alter table Course
drop constraint FK_COURSE_REFERENCE_TEACHER
goif exists (select 1
from dbo.sysreferences r join dbo.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('SC') and o.name = 'FK_SC_REFERENCE_COURSE')
alter table SC
drop constraint FK_SC_REFERENCE_COURSE
goif exists (select 1
from dbo.sysreferences r join dbo.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('SC') and o.name = 'FK_SC_REFERENCE_STUDENT')
alter table SC
drop constraint FK_SC_REFERENCE_STUDENT
goif exists (select 1
from sysobjects
where id = object_id('Course')
and type = 'U')
drop table Course
goif exists (select 1
from sysobjects
where id = object_id('SC')
and type = 'U')
drop table SC
goif exists (select 1
from sysobjects
where id = object_id('Student')
and type = 'U')
drop table Student
goif exists (select 1
from sysobjects
where id = object_id('Teacher')
and type = 'U')
drop table Teacher
go/*==============================================================*/
/* Table: Course */
/*==============================================================*/
create table Course (
C# int not null,
Cname nvarchar(255) not null,
T# int not null,
constraint PK_COURSE primary key (C#)
)
go/*==============================================================*/
/* Table: SC */
/*==============================================================*/
create table SC (
S# int not null,
C# int not null,
score float not null
)
go/*==============================================================*/
/* Table: Student */
/*==============================================================*/
create table Student (
S# int not null,
Sname nvarchar(255) not null,
Sage int not null,
Ssex nvarchar(255) not null,
constraint PK_STUDENT primary key (S#)
)
go/*==============================================================*/
/* Table: Teacher */
/*==============================================================*/
create table Teacher (
T# int not null,
Tname nvarchar(255) not null,
constraint PK_TEACHER primary key (T#)
)
goalter table Course
add constraint FK_COURSE_REFERENCE_TEACHER foreign key (T#)
references Teacher (T#)
goalter table SC
add constraint FK_SC_REFERENCE_COURSE foreign key (C#)
references Course (C#)
goalter table SC
add constraint FK_SC_REFERENCE_STUDENT foreign key (S#)
references Student (S#)
go
/* DBMS name: ORACLE Version 10g */
/* Created on: 2010-6-2 22:41:51 */
/*==============================================================*/
alter table "dbo"."Course"
drop constraint FK_COURSE_REFERENCE_TEACHER;alter table "dbo".SC
drop constraint FK_SC_REFERENCE_COURSE;alter table "dbo".SC
drop constraint FK_SC_REFERENCE_STUDENT;drop index "dbo"."_WA_Sys_T#_4222D4EF";drop index "dbo"."_WA_Sys_Cname_4222D4EF";drop table "dbo"."Course" cascade constraints;drop index "dbo"."_WA_Sys_score_440B1D61";drop index "dbo"."_WA_Sys_S#_440B1D61";drop index "dbo"."_WA_Sys_C#_440B1D61";drop table "dbo".SC cascade constraints;drop table "dbo"."Student" cascade constraints;drop index "dbo"."_WA_Sys_Tname_46E78A0C";drop table "dbo"."Teacher" cascade constraints;drop user "dbo";/*==============================================================*/
/* User: "dbo" */
/*==============================================================*/
create user "dbo" identified by '';/*==============================================================*/
/* Table: "Course" */
/*==============================================================*/
create table "dbo"."Course" (
C# INTEGER not null,
"Cname" NVARCHAR2(30) not null,
T# INTEGER not null,
constraint PK_COURSE primary key (C#)
);/*==============================================================*/
/* Index: "_WA_Sys_Cname_4222D4EF" */
/*==============================================================*/
create index "dbo"."_WA_Sys_Cname_4222D4EF" on "dbo"."Course" (
"Cname" ASC
);/*==============================================================*/
/* Index: "_WA_Sys_T#_4222D4EF" */
/*==============================================================*/
create index "dbo"."_WA_Sys_T#_4222D4EF" on "dbo"."Course" (
T# ASC
);/*==============================================================*/
/* Table: SC */
/*==============================================================*/
create table "dbo".SC (
S# INTEGER not null,
C# INTEGER not null,
"score" FLOAT not null
);/*==============================================================*/
/* Index: "_WA_Sys_C#_440B1D61" */
/*==============================================================*/
create index "dbo"."_WA_Sys_C#_440B1D61" on "dbo".SC (
C# ASC
);/*==============================================================*/
/* Index: "_WA_Sys_S#_440B1D61" */
/*==============================================================*/
create index "dbo"."_WA_Sys_S#_440B1D61" on "dbo".SC (
S# ASC
);/*==============================================================*/
/* Index: "_WA_Sys_score_440B1D61" */
/*==============================================================*/
create index "dbo"."_WA_Sys_score_440B1D61" on "dbo".SC (
"score" ASC
);/*==============================================================*/
/* Table: "Student" */
/*==============================================================*/
create table "dbo"."Student" (
S# INTEGER not null,
"Sname" NVARCHAR2(6) not null,
"Sage" INTEGER not null,
"Ssex" NVARCHAR2(6) not null,
constraint PK_STUDENT primary key (S#)
);/*==============================================================*/
/* Table: "Teacher" */
/*==============================================================*/
create table "dbo"."Teacher" (
T# INTEGER not null,
"Tname" NVARCHAR2(6) not null,
constraint PK_TEACHER primary key (T#)
);/*==============================================================*/
/* Index: "_WA_Sys_Tname_46E78A0C" */
/*==============================================================*/
create index "dbo"."_WA_Sys_Tname_46E78A0C" on "dbo"."Teacher" (
"Tname" ASC
);alter table "dbo"."Course"
add constraint FK_COURSE_REFERENCE_TEACHER foreign key (T#)
references "dbo"."Teacher" (T#);alter table "dbo".SC
add constraint FK_SC_REFERENCE_COURSE foreign key (C#)
references "dbo"."Course" (C#);alter table "dbo".SC
add constraint FK_SC_REFERENCE_STUDENT foreign key (S#)
references "dbo"."Student" (S#);
嘿嘿
不知楼主要用什么,所以弄了MYSQL的