数据库建表

发布网友 发布时间:2022-04-22 15:43

我来回答

1个回答

热心网友 时间:2022-04-09 12:43

CREATE TABLE [学生] (
[学号] [int] NOT NULL ,
[姓名] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[性别] [nvarchar] (1) COLLATE Chinese_PRC_CI_AS NULL ,
[系号] [int] NULL ,
[年龄] [int] NULL
) ON [PRIMARY]

CREATE TABLE [系表] (
[系号] [int] NOT NULL ,
[系名] [nvarchar] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[系主任] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]

ALTER TABLE [学生] ADD
CONSTRAINT [PK_学生] PRIMARY KEY CLUSTERED
(
[学号]
) ON [PRIMARY]

ALTER TABLE [系表] ADD
CONSTRAINT [PK_系表] PRIMARY KEY CLUSTERED
(
[系号]
) ON [PRIMARY]

ALTER TABLE [学生] ADD
CONSTRAINT [FK_学生_系表] FOREIGN KEY
(
[系号]
) REFERENCES [系表] (
[系号]
) ON DELETE CASCADE ON UPDATE CASCADE

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com