简体   繁体   English

SQL表-此设计可接受/良好实践吗?

[英]SQL Tables - Is this design acceptable/good practice?

I'm in the process of developing/designing a small system to keep track of servers, what applications run on these servers, and for each application what environments exists on the server. 我正在开发/设计一个小型系统,以跟踪服务器,这些服务器上运行的应用程序以及服务器上存在的每个应用程序的环境。 I have a quick question about good design patterns/practices. 我有一个关于好的设计模式/实践的快速问题。

I have 3 tables, one for each entity. 我有3张桌子,每个实体一张。 They are (abbreviated) as follows: 它们(缩写)如下:

Server
Id : int

Application
Id : int

Environment
Id : int

Now, my question is: 现在,我的问题是:

Would it be acceptable to create a joining table as such: 创建这样的联接表是否可以接受:

AppServerEnvironments
ServerId : int
ApplicationId : int
EnvironmentId : int

Or, is it better practice to create two joining tables as such: 或者,最好这样创建两个联接表:

ApplicationServer
ServerId : int
ApplicationId : int

ApplicationEnvironment
ApplicationId : int
EnvironmentId : int

I've tried going with the second option, but cannot seem to figure out a way to join all 3 tables properly. 我尝试使用第二个选项,但似乎无法找出正确连接所有3个表的方法。

Any input/guidance is greatly appreciated. 任何输入/指导,不胜感激。

Thank you! 谢谢!

so you would have something like this: 所以你会有这样的事情:

application
-----------
application_id

server
-----------
server_id

application_instance
---------------------
application_id
instance_id
name <- name this one DEV, or PROD etc.
description <-  here describe the use of the DEV system

now say which one lives where... 现在说出哪一个住在哪里...

server_instance
---------------
server_id
instance_id

It depends. 这取决于。 If you require all three keys to be present in the joins, then you should go for the AppServerEnvironments solution. 如果要求所有三个键都出现在联接中,则应使用AppServerEnvironments解决方案。 If the Server/Application pair does not require an Enviroment or the Application/Environment does not require a Server , then you'd best use the ApplicationServer/ApplicationEnvironment solution. 如果Server/Application对不需要Enviroment或者Application/Environment不需要Server ,那么最好使用ApplicationServer/ApplicationEnvironment解决方案。 This way, you can define composite primary keys on the tables without having NULL values. 这样,您可以在表上定义复合主键而没有NULL值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM