CREATE TABLE 循环 ER Table 语句
CREATE TABLE statement of looped ER Table
所以我需要创建此 ER Table 的 CREATE TABLE
语句。我知道通常如何创建这些语句,但我不知道如何使用这些循环语句。我需要你的帮助。
关于这个 table 我只有这个;
Q2
Convert the following ER diagram into relational model. Write the “CREATE TABLE”
statements. Don’t forget to specify the primary keys and foreign keys.
我目前最好的猜测是类似的东西。
USE [database_name]
GO
CREATE TABLE t_employee (
eid INT IDENTITY(1,1)
, name NVARCHAR(50) );
CREATE TABLE t_reports (
report_id INT IDENTITY (1,1)
, eid INT );
ALTER TABLE t_reports
ADD FOREIGN KEY (eid) REFERENCES t_employee(eid);
澄清一下,这是 SQL Server
语法,但它应该适用于常见的 RMDB,除了 Oracle
几乎使用 SQL
语法。
在 MySql 语法中:
create table employee
eid int not null primary key,
name varchar not null,
reports int foreign key references employee(eid) on update cascade on delete set null
注意:这实现了 1:N,因此是一个层次结构。
所以我需要创建此 ER Table 的 CREATE TABLE
语句。我知道通常如何创建这些语句,但我不知道如何使用这些循环语句。我需要你的帮助。
关于这个 table 我只有这个;
Q2 Convert the following ER diagram into relational model. Write the “CREATE TABLE” statements. Don’t forget to specify the primary keys and foreign keys.
我目前最好的猜测是类似的东西。
USE [database_name]
GO
CREATE TABLE t_employee (
eid INT IDENTITY(1,1)
, name NVARCHAR(50) );
CREATE TABLE t_reports (
report_id INT IDENTITY (1,1)
, eid INT );
ALTER TABLE t_reports
ADD FOREIGN KEY (eid) REFERENCES t_employee(eid);
澄清一下,这是 SQL Server
语法,但它应该适用于常见的 RMDB,除了 Oracle
几乎使用 SQL
语法。
在 MySql 语法中:
create table employee
eid int not null primary key,
name varchar not null,
reports int foreign key references employee(eid) on update cascade on delete set null
注意:这实现了 1:N,因此是一个层次结构。