私の質問です:私は多くのテーブルにMvrIdを入れていることに注意してください。あなたの意見は以下の通りです。どうすれば改善できますか?あなたが私を本に向けると、私は本のページに行きたいと思う。 全体を見たい場合は、このスクリプトをMedicalVarianceというデータベースで実行することができます。データベース設計SQL
USE MedicalVariance;
--This is a quick install script
--I guess you could even execute this from the front end but that would be overkill
--Because of the audience that will install this software are DBA's
IF EXISTS
(
--The query below will will evaluate to true if it finds a foreign key constraint.
SELECT 1 From INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE LIKE 'FOREIGN KEY'
)
BEGIN
DECLARE @TableName NVARCHAR(100)
DECLARE @ConstraintName NVARCHAR(100)
DECLARE @DynamicSQLEXEC NVARCHAR(300)
--DECLARE AND FEED THE CURSOR DATA
Declare ConstraintCursor CURSOR FAST_FORWARD FOR
-- Dont worry I wont drop your precious FOREIGN KEYS since the catalog must be MedicalVariance
SELECT TABLE_NAME,CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS
WHERE CONSTRAINT_TYPE LIKE 'FOREIGN KEY'
AND
CONSTRAINT_CATALOG LIKE 'MedicalVariance'
--OPEN THE CURSOR
OPEN ConstraintCursor
FETCH NEXT FROM ConstraintCursor
INTO @TableName, @ConstraintName
--NOW IMPLEMENT THE LOGIC TO DROP ALL CONSTRAINTS
WHILE @@FETCH_STATUS =0
BEGIN
--DYNAMIC SQL IS A PAIN IF YOU THINK YOU GOT BETTER SYNTAX GO FOR IT
SET @DynamicSQLEXEC ='ALTER TABLE '-- the space is important
SET @DynamicSQLEXEC [email protected] + @TableName + ' '
SET @DynamicSQLEXEC [email protected] + 'DROP CONSTRAINT '
SET @DynamicSQLEXEC [email protected] + @ConstraintName
PRINT @DynamicSQLEXEC -- make sure this is correct sql syntax
EXEC(@DynamicSQLEXEC)
-----------------------Dynamic SQL ENDS-------------------------------------
FETCH NEXT FROM ConstraintCursor
INTO @TableName, @ConstraintName
END;
CLOSE ConstraintCursor
DEALLOCATE ConstraintCursor
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMeds'
)
BEGIN
DROP TABLE MvrMeds
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'Mvr'
)
BEGIN
DROP TABLE dbo.Mvr
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMedsAdminRoute'
)
BEGIN
DROP TABLE dbo.MvrMedsAdminRoute
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMedsPrescribingErrors'
)
BEGIN
DROP TABLE dbo.MvrMedsPrescribingErrors
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMedsTranscribingErrors'
)
BEGIN
DROP TABLE dbo.MvrMedsTranscribingErrors
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMedsProductIssuesErrors'
)
BEGIN
DROP TABLE dbo.MvrMedsProductIssuesErrors
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMedsProcumentErrors'
)
BEGIN
DROP TABLE dbo.MvrMedsProcumentErrors
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMedsDispensingErrors'
)
BEGIN
DROP TABLE dbo.MvrMedsDispensingErrors
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMedsAdministrationErrors'
)
BEGIN
DROP TABLE dbo.MvrMedsAdministrationErrors
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrMedsDocumentationErrors'
)
BEGIN
DROP TABLE dbo.MvrMedsDocumentationErrors
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrEmployees'
)
BEGIN
DROP TABLE dbo.MvrEmployees
END;
GO
IF EXISTS
(
SELECT 1 FROM Information_Schema.Tables
WHERE Table_Name = 'MvrCommunicationErrors'
)
BEGIN
DROP TABLE dbo.MvrCommunicationErrors
END;
GO
-- The way I am putting MvrId in almost every table
-- Do you recommend it or bless it as good desing?
CREATE TABLE Mvr
(
MvrId INT NOT NULL PRIMARY KEY
)
CREATE TABLE MvrMedsAdminRoute
(
MvrMedsAdminRouteId INT NOT NULL PRIMARY KEY,
MvrId INT
)
CREATE TABLE MvrMeds
(
MvrMedsId INT NOT NULL PRIMARY KEY,
MvrId INT ,
MvrMedsAdminRouteId INT ,
CONSTRAINT MvrMeds_Mvr_FK FOREIGN KEY(MvrId) REFERENCES dbo.Mvr(MvrID),
CONSTRAINT MvrMeds_MvrMedsAdminRoute_FK FOREIGN KEY (MvrMedsAdminRouteId) REFERENCES dbo.MvrMedsAdminRoute(MvrMedsAdminRouteId)
)
CREATE TABLE MvrMedsPrescribingErrors
(
MvrPrescribingErrorId INT NOT NULL PRIMARY KEY,
MvrMedsId INT ,
MvrId INT
CONSTRAINT MvrMedsPrescribingErrors_MvrMeds_FK FOREIGN KEY (MvrMedsId) REFERENCES dbo.MvrMeds(MvrMedsId)
)
CREATE TABLE MvrMedsTranscribingErrors
(
MvrTranscribingErrorsId INT NOT NULL PRIMARY KEY,
MvrMedsId INT ,
MvrId INT
CONSTRAINT MvrMedsTranscribingErrors_MvrMeds_FK FOREIGN KEY (MvrMedsId) REFERENCES dbo.MvrMeds(MvrMedsId)
)
CREATE TABLE MvrMedsProductIssuesErrors
(
MvrTranscribingErrorsId INT NOT NULL PRIMARY KEY,
MvrMedsId INT ,
MvrId INT
CONSTRAINT MvrMedsProductIssuesErrors_MvrMeds_FK FOREIGN KEY (MvrMedsId) REFERENCES dbo.MvrMeds(MvrMedsId)
)
CREATE TABLE MvrMedsProcumentErrors
(
MvrProcumentErrorsId INT NOT NULL PRIMARY KEY,
MvrMedsId INT,
MvrId INT
CONSTRAINT MvrMedsOrderingProcumentErrors_MvrMeds_FK FOREIGN KEY (MvrMedsId) REFERENCES dbo.MvrMeds(MvrMedsId)
)
CREATE TABLE MvrMedsDispensingErrors
(
MvrDispensingErrorsId INT NOT NULL PRIMARY KEY,
MvrMedsId INT,
MvrId INT
CONSTRAINT MvrMedsDispensingErrors_MvrMeds_FK FOREIGN KEY (MvrMedsId) REFERENCES dbo.MvrMeds(MvrMedsId)
)
CREATE TABLE MvrMedsAdministrationErrors
(
MvrAdministrationErrorsId INT NOT NULL PRIMARY KEY,
MvrMedsId INT,
MvrId INT
CONSTRAINT MvrMedsAdministrationErrors_MvrMeds_FK FOREIGN KEY (MvrMedsId) REFERENCES dbo.MvrMeds(MvrMedsId)
)
CREATE TABLE MvrMedsDocumentationErrors
(
MvrDocumentationErrorsId INT NOT NULL PRIMARY KEY,
MvrMedsId INT,
MvrId INT
CONSTRAINT MvrMedsDocumentationErrors_MvrMeds_FK FOREIGN KEY (MvrMedsId) REFERENCES dbo.MvrMeds(MvrMedsId)
)
----EMPLOYEES
--ONLY EMPLOYEES CAN BE PART OF MVR?
CREATE TABLE MvrEmployees
(
MvrEmployeesId INT PRIMARY KEY,
MvrId INT,
CONSTRAINT MvrEmployees_Mvr_FK FOREIGN KEY (MvrId) REFERENCES dbo.Mvr(MvrId)
)
CREATE TABLE MvrCommunicationErrors
(
MvrCommunicationErrorsId INT NOT NULL PRIMARY KEY,
MvrEmployeesId INT,
MvrId INT,
CONSTRAINT MvrCommunicationErrors_MvrEmployees_FK FOREIGN KEY (MvrEmployeesId) REFERENCES dbo.MvrEmployees(MvrEmployeesId)
)
で
MvrId
を持つことが絶対に必要ですご質問、大量のコードをダンプして、人々にどのようなことを考えるか尋ねないでください。他人が理解できる具体的な質問をする。 –すべてのテーブルがコアオブジェクトに関連している場合は、各テーブルの特定のフィールドに問題はありません。それを超えて私は何を言うべきか分からない... – mellamokb
ありがとう、私は特定の質問をしたと思う。問題は、メラモクが言ったように、すべてのテーブルに特定のフィールドを置くことについてどう思いますか。コードは単なる参考用です。 – hidden