السلام عليكم ورحمة الله وبركاته
عندي سكيما ديجرام عن شركة معينة وكنت بحاجه الى تحويلها الى داتا بيس عن طريق الاكواد فكتبت الكود الاتى ولكن يظهر لى خطأ انه لا يوجد جدول اسمه
department
فما هو الناقص فى الكود جزاكم الله خيرا
USE [Company] IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[depertment]') AND type in (N'U')) DROP TABLE [dbo].[depertment] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[dept_location]') AND type in (N'U')) DROP TABLE [dbo].[dept_location] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[project]') AND type in (N'U')) DROP TABLE [dbo].[project] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[work_on]') AND type in (N'U')) DROP TABLE [dbo].[work_on] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[dependant]') AND type in (N'U')) DROP TABLE [dbo].[dependant] GO SET ANSI_NULLS ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id= OBJECT_ID(N'[dbo].[Employee]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Employee] ( Fname VARCHAR(15) NOT NULL, Minit CHAR, Lname VARCHAR(15) NOT NULL, Ssn CHAR(9) NOT NULL, Bdate DATETime, Address VARCHAR(30), Sex CHAR, Salary DECIMAL(10,2), Super_ssn CHAR(9), Dno INT NOT NULL, PRIMARY Key (Ssn), Foreign Key (Super_ssn) REFERENCES employee(Ssn), Foreign Key (Dno) REFERENCES Department(Dnumber)); END GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id= OBJECT_ID(N'[dbo].[Department]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Department] (Dname VARCHAR(15) NOT NULL, Dnumber INT NOT NULL, Mgr_ssn CHAR(9), Mgr_start_date DATEtime, PRIMARY KEY (Dnumber), UNIQUE(Dname), Foreign KEY (Mgr_ssn) REFERENCES Employee(Ssn)); END GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id= OBJECT_ID(N'[dbo].[dept_location]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[dept_location] (Dnumber INT NOT NULL, Dlocation VARCHAR(15) NOT NULL, PRIMARY KEY(Dnumber,Dlocation), Foreign KEY(Dnumber) REFERENCES department(Dnumber)); END GO IF NOT EXISTS(SELECT * FROM sys.objects WHERE object_id=OBJECT_ID(N'[dbo].[project]')AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Project] ( Pname varchar(15) Not null, Pnumber int not null, Plocation varchar(15), Dnum int not null, Primary Key (Pnumber), Unique (Pname), Foreign key (Dnum) references Department(Dnumber)); End GO IF NOT EXISTS(SELECT * FROM sys.objects WHERE object_id=OBJECT_ID(N'[dbo].[Work_on]')AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Work_on] ( Essn Char(9) not null, Pno int not null, Hours Decimal(3,1) not null, Primary Key(Essn,Pno), Foreign Key (Essn) References Employee(Snn), Foreign Key (Pno) References Project(pnumber)); End GO IF NOT EXISTS(SELECT * FROM sys.objects WHERE object_id=OBJECT_ID(N'[dbo].[Dependant]')AND type in (N'U')) BEGIN CREATE TABLE [dbo].[Dependant] ( Essn Char(9) not null, Deendant_name varchar(15) not null, Sex char, Bdate datetime, Relationship varchar(8), Primary Key (Essn,Dependant_name), Foreign Key(Essn) References Employee(Ssn)); End
فيظهر لى الاخطا الاتية
Msg 1767, Level 16, State 0, Line 4
Foreign key 'FK__Employee__Dno__793DFFAF' references invalid table 'Department'.
Msg 1750, Level 16, State 0, Line 4
Could not create constraint. See previous errors.
Msg 1767, Level 16, State 0, Line 5
Foreign key 'FK__Departmen__Mgr_s__7D0E9093' references invalid table 'Employee'.
Msg 1750, Level 16, State 0, Line 5
Could not create constraint. See previous errors.
Msg 1767, Level 16, State 0, Line 5
Foreign key 'FK__dept_loca__Dnumb__7FEAFD3E' references invalid table 'department'.
Msg 1750, Level 16, State 0, Line 5
Could not create constraint. See previous errors.
Msg 1767, Level 16, State 0, Line 4
Foreign key 'FK__Project__Dnum__03BB8E22' references invalid table 'Department'.
Msg 1750, Level 16, State 0, Line 4
Could not create constraint. See previous errors.
Msg 1767, Level 16, State 0, Line 3
Foreign key 'FK__Work_on__Essn__0697FACD' references invalid table 'Employee'.
Msg 1750, Level 16, State 0, Line 3
Could not create constraint. See previous errors.
Msg 1911, Level 16, State 1, Line 4
Column name 'Dependant_name' does not exist in the target table or view.
Msg 1750, Level 16, State 0, Line 4
Could not create constraint. See previous errors.