他の人が既に述べたように、電話と通信事業者の間の関係を格納するテーブルが必要です。これを示すテスト スキーマを作成しました。
USE Test;
CREATE TABLE Phones
(
PhoneID INT NOT NULL CONSTRAINT PK_Phones_PhoneID PRIMARY KEY CLUSTERED IDENTITY(1,1)
, PhoneName NVARCHAR(255) NOT NULL
);
CREATE TABLE Carriers
(
CarrierID INT NOT NULL CONSTRAINT PK_Carriers_CarrierID PRIMARY KEY CLUSTERED IDENTITY(1,1)
, CarrierName NVARCHAR(255) NOT NULL
);
CREATE TABLE PhonesCarriersXRef
(
PhoneID INT NOT NULL CONSTRAINT FK_PhonesCarriersXRef_Phones_PhoneID FOREIGN KEY REFERENCES Phones (PhoneID) ON DELETE CASCADE ON UPDATE CASCADE
, CarrierID INT NOT NULL CONSTRAINT FK_PhonesCarriersXRef_Carriers_CarrierID FOREIGN KEY REFERENCES Carriers (CarrierID) ON DELETE CASCADE ON UPDATE CASCADE
CONSTRAINT PK_PhonesCarriersXRef PRIMARY KEY CLUSTERED (PhoneID, CarrierID)
);
INSERT INTO Phones (PhoneName) VALUES ('Nokia Lumia 1020');
INSERT INTO Phones (PhoneName) VALUES ('Nokia Lumia 920');
INSERT INTO Carriers (CarrierName) VALUES ('AT&T');
INSERT INTO Carriers (CarrierName) VALUES ('Verizon');
INSERT INTO PhonesCarriersXRef (PhoneID, CarrierID) VALUES (1,1);
INSERT INTO PhonesCarriersXRef (PhoneID, CarrierID) VALUES (1,2);
INSERT INTO PhonesCarriersXRef (PhoneID, CarrierID) VALUES (2,1);
INSERT INTO PhonesCarriersXRef (PhoneID, CarrierID) VALUES (2,2);
SELECT C.CarrierName, P.PhoneName
FROM PhonesCarriersXRef X
INNER JOIN Phones P ON X.PhoneID = P.PhoneID
INNER JOIN Carriers C ON X.CarrierID = C.CarrierID
ORDER BY C.CarrierName, P.PhoneName;
これは以下を返します。