My situation is i have four tables Patient, Receipt, Clinic and Laboratory.
CREATE DATABASE TestHosp
GO
USE TestHosp
GO
Information about patient
CREATE TABLE Patient
(Id INT Not NULL PRIMARY KEY IDENTITY(1,1),
FirestName VARCHAR(12) NOT NULL,
LastName VARCHAR(12) NOT NULL,
Birthday DATETIME)
CREATE TABLE Clinic
(Id INT NOT NULL PRIMARY KEY IDENTITY(1,1),
ClinicName VARCHAR(20) UNIQUE,
Price DECIMAL(8,2))
CREATE TABLE Laboratory
(Id INT NOT NULL PRIMARY KEY IDENTITY(1,1),
LaboratoryName VARCHAR(20) UNIQUE,
Price DECIMAL (8,2))
Note that the receipt contains a receipt number, One receipt belongs to one laboratory, One receipt belongs to one clinic i want do relation without create two column FK_Laboratory_ID and FK_Clinic_ID and one number for all receipt any way to do this.
CREATE TABLE Receipt
(Id INT NOT NULL PRIMARY KEY IDENTITY(1,1),
PatientID INT NOT NULL
CONSTRAINT [FK_Patient_ID] FOREIGN KEY (PatientID) REFERENCES Patient(Id),
DATE DATETIME,
Paid DECIMAL(8,2))