以下は私のCREATE TABLE
スクリプトです:
CREATE TABLE Person
(
ID INT Primary Key Identity (1,1),
LastName nVarchar (20) not NULL,
FirstName nVarchar (20) not NULL,
MiddleName nVarchar (20),
BirthDate DateTime not NULL,
Age INT not NULL,
Check (Age18)
);
CREATE TABLE Department
(
ID INT Primary Key Identity (1,1),
DepartmentName nVarchar (50) Unique,
DepartmentCode nVarchar (20) Unique,
IsActive Bit Default (1)
);
CREATE TABLE Employee
(
ID INT Primary Key Identity (1,1),
PersonId INT Foreign Key REFERENCES Person,
DepartmentId INT Foreign Key REFERENCES Department,
Salary Decimal (18,2),
Check (Salary10000),
IsActive Bit Default (1)
);
以下は私のINSERT
スクリプトです:
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Dela Cruz','Juan',NULL,01/01/199,22)
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Dela Cerna','Pedro','Juan',11/01/1993,21)
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Villaflores','Rachel','Diacoma',10/7/1990,24)
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Abendan','Marnell',NULL,03/15/1989,25)
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Oplado','Aiza','Tapayan',11/18/1993,21)
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Loreto','Desire','Talingting',06/10/1993,21)
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Magbanua','Prince Laurence','Rallos',05/25/1992,22)
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Locsin','Franz Cyril',NULL,02/14/1993,21)
INSERT INTO Person (LastName, FirstName, MiddleName,BirthDate,Age)
VALUES ('Dela Pena','Precious',NULL,01/01/199,21)
INSERT INTO Department (DepartmentName, DepartmentCode, IsActive)
VALUES ('ITDepartment','ItDept',1)
INSERT INTO Department (DepartmentName, DepartmentCode, IsActive)
VALUES ('EngineeringDepartment','EDept',1)
INSERT INTO Department (DepartmentName, DepartmentCode, IsActive)
VALUES ('ComputerScienceDepartment','CSDept',1)
INSERT INTO Department (DepartmentName, DepartmentCode, IsActive)
VALUES ('InformationSystemDepartment','ISDept',1)
INSERT INTO Department (DepartmentName, DepartmentCode, IsActive)
VALUES ('BusinessAdministrationDepartment','BADept',1)
INSERT INTO Department (DepartmentName, DepartmentCode, IsActive)
VALUES ('ElementaryDepartment','ElemDept',1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (1,2,12000,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (2,4,10001,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (3,6,13000,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (4,1,25000,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (5,3,15000,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (6,5,10002,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (7,1,56000,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (8,4,14000,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (9,6,15900,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (2,4,12300,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (4,1,13500,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (6,3,14300,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (8,5,12500,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (1,2,11460,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (3,4,10910,1)
INSERT INTO Employee (PersonId,DepartmentId,Salary,IsActive)
VALUES (5,6,10001,1)
以下は私の選択スクリプトです:
SELECT
Person.LastName, Department.DepartmentName
FROM
Person, Department
FULL OUTER JOIN
Employee ON Employee.PersonId = Employee.DepartmentId
これは正しくない結果です。これには何が正しいのかわかりません。JOINSは初めてです。
Dela Cruz BusinessAdministrationDepartment
Dela Cerna BusinessAdministrationDepartment
Villaflores BusinessAdministrationDepartment
Abendan BusinessAdministrationDepartment
Oplado BusinessAdministrationDepartment
Loreto BusinessAdministrationDepartment
Magbanua BusinessAdministrationDepartment
Locsin BusinessAdministrationDepartment
Dela Pena BusinessAdministrationDepartment
Dela Cruz ComputerScienceDepartment
Dela Cerna ComputerScienceDepartment
Villaflores ComputerScienceDepartment
Abendan ComputerScienceDepartment
Oplado ComputerScienceDepartment
Loreto ComputerScienceDepartment
Magbanua ComputerScienceDepartment
Locsin ComputerScienceDepartment
Dela Pena ComputerScienceDepartment
長くなりすぎるので、コンピューターサイエンス部門に立ち寄りました。どうすればこれを正しく理解できますか? 助けてください。ありがとう!:)