SQL Server还是c#中的数据库设计?

时间:2021-11-15 12:48:18

Should a database be designed on SQL Server or C#?

应该在SQL Server或c#上设计数据库吗?

I always thought it was more appropriate to design it on SQL Server, but recently I started reading a book (Pro ASP.NET MVC Framework) which, to my understanding, basically says that it's probably a better idea to write it in C# since you will be accessing the model through C#, which does make sense.

我一直认为在SQL Server上设计它更合适,但最近我开始读一本书(Pro ASP)。根据我的理解,用c#编写它可能是一个更好的主意,因为您将通过c#访问模型,这是有意义的。

I was wondering what everyone else's opinion on this matter was...

我想知道其他人对这件事的看法是什么……

I mean, for example, do you consider "correct" having a table that specifies constants (like an AccessLevel table that is always supposed to contain

我的意思是,例如,您是否认为拥有一个指定常量的表是“正确的”

1 Everyone
2 Developers
3 Administrators
4 Supervisors
5 Restricted

每个人2个开发人员3个管理员4个管理员5个限制

Wouldn't it be more robust and streamlined to just have an enum for that same purpose?

仅仅为了同样的目的建立一个enum难道不是更健壮、更精简吗?

4 个解决方案

#1


5  

A database schema should be designed on paper or with an ERD tool.

数据库模式应该在纸上或使用ERD工具进行设计。

It should be implemented in the database.

它应该在数据库中实现。

Are you thinking about ORMs like Entity Framework that let you use code to generate the database?

您是否正在考虑使用代码生成数据库的ORMs类实体框架?

Personally, I would rather think through my design on paper before committing it to a DB myself. I would be happy to use an ORM or class generator from this DB later on.

就我个人而言,在提交给DB之前,我宁愿在纸上仔细考虑我的设计。稍后我很乐意使用来自这个DB的ORM或类生成器。

#2


0  

Before VS.NET 2010 I was using SQL Server Management Studio to design my databases, now I am using EF 4.0 designer, for me it's the best way to go.

在VS.NET 2010之前,我使用SQL Server Management Studio来设计我的数据库,现在我使用EF 4.0 designer,对我来说这是最好的方式。

#3


0  

If your problem domain is complex or its complexity grows as the system evolves you'll soon discover you need some meta data to make life easier. C# can be a good choice as a host language for such stuff as you can utilize its type-system to enforce some invariants (like char-columns length, null/not null restrictions or check-constraints; you can declared it as consts, enums, etc). Unfortunately i don't know utilities (sqlmetal.exe can export some meta but only as xml) that can do it out of the box, although some CASE tools probably can be customized. I'd go for some custom-made generator to produce the db schema from C# (just a few hours work comparing to learning, for example, customization options offered by Sybase PowerDesigner).

如果您的问题域是复杂的,或者随着系统的发展其复杂性增加,您将很快发现您需要一些元数据来简化工作。c#作为宿主语言是一种很好的选择,因为您可以使用它的类型系统来执行一些不变量(如字符列长度、null/not null限制或检查约束);您可以将它声明为consts、enums等)。不幸的是,我不知道实用程序(sqlmetal)。exe可以导出一些元数据,但只能导出为xml),这样就可以将其从框中删除,尽管一些CASE工具可能是可以定制的。我将使用一些定制的生成器从c#生成db模式(与Sybase PowerDesigner提供的定制选项相比,只需要几个小时的工作)。

#4


0  

ORMs have their place, that place is NOT database design. There are many considerations in designing a database that need to be thought through not automatically generated no matter how appealing the idea of not thinking about design might be. There are often many things that need to be considered that have nothing to do with the application, things like data integrity, reporting, audit tables and data imports. Using an ORM to create a database that looks like an object model may not be the best design for performance and may not have the the things you really need in terms of data integrity. Remember even if you think nothing except the application will touch the database ever, this is not true. At some point the data base will need to have someone do a major data revision (to fix a problem) that is done directly on the database not through the application. At somepoint you are going to need need to import a million records from some other company you just bought and are goping to need an ETL process outside teh application. Putting all your hopes and dreams for the database (as well as your data integrity rules) is short-sighted.

ORMs有自己的位置,那不是数据库设计。在设计一个数据库时,有很多需要考虑的事项,不管不考虑设计的想法有多吸引人,都需要通过不自动生成来考虑。通常需要考虑许多与应用程序无关的事情,比如数据完整性、报告、审计表和数据导入。使用ORM创建一个看起来像对象模型的数据库,可能不是性能的最佳设计,也可能没有您真正需要的数据完整性。请记住,即使您认为除了应用程序之外什么都不会碰到数据库,这也不是真的。在某些情况下,数据库将需要有人进行主要的数据修改(以修复问题),这些修改是直接在数据库上完成的,而不是通过应用程序完成的。在某一时刻,您需要从刚刚购买的其他公司中导入100万份记录,并在teh应用程序之外需要一个ETL流程。将您对数据库(以及您的数据完整性规则)的所有希望和梦想放在一起是短视的。

#1


5  

A database schema should be designed on paper or with an ERD tool.

数据库模式应该在纸上或使用ERD工具进行设计。

It should be implemented in the database.

它应该在数据库中实现。

Are you thinking about ORMs like Entity Framework that let you use code to generate the database?

您是否正在考虑使用代码生成数据库的ORMs类实体框架?

Personally, I would rather think through my design on paper before committing it to a DB myself. I would be happy to use an ORM or class generator from this DB later on.

就我个人而言,在提交给DB之前,我宁愿在纸上仔细考虑我的设计。稍后我很乐意使用来自这个DB的ORM或类生成器。

#2


0  

Before VS.NET 2010 I was using SQL Server Management Studio to design my databases, now I am using EF 4.0 designer, for me it's the best way to go.

在VS.NET 2010之前,我使用SQL Server Management Studio来设计我的数据库,现在我使用EF 4.0 designer,对我来说这是最好的方式。

#3


0  

If your problem domain is complex or its complexity grows as the system evolves you'll soon discover you need some meta data to make life easier. C# can be a good choice as a host language for such stuff as you can utilize its type-system to enforce some invariants (like char-columns length, null/not null restrictions or check-constraints; you can declared it as consts, enums, etc). Unfortunately i don't know utilities (sqlmetal.exe can export some meta but only as xml) that can do it out of the box, although some CASE tools probably can be customized. I'd go for some custom-made generator to produce the db schema from C# (just a few hours work comparing to learning, for example, customization options offered by Sybase PowerDesigner).

如果您的问题域是复杂的,或者随着系统的发展其复杂性增加,您将很快发现您需要一些元数据来简化工作。c#作为宿主语言是一种很好的选择,因为您可以使用它的类型系统来执行一些不变量(如字符列长度、null/not null限制或检查约束);您可以将它声明为consts、enums等)。不幸的是,我不知道实用程序(sqlmetal)。exe可以导出一些元数据,但只能导出为xml),这样就可以将其从框中删除,尽管一些CASE工具可能是可以定制的。我将使用一些定制的生成器从c#生成db模式(与Sybase PowerDesigner提供的定制选项相比,只需要几个小时的工作)。

#4


0  

ORMs have their place, that place is NOT database design. There are many considerations in designing a database that need to be thought through not automatically generated no matter how appealing the idea of not thinking about design might be. There are often many things that need to be considered that have nothing to do with the application, things like data integrity, reporting, audit tables and data imports. Using an ORM to create a database that looks like an object model may not be the best design for performance and may not have the the things you really need in terms of data integrity. Remember even if you think nothing except the application will touch the database ever, this is not true. At some point the data base will need to have someone do a major data revision (to fix a problem) that is done directly on the database not through the application. At somepoint you are going to need need to import a million records from some other company you just bought and are goping to need an ETL process outside teh application. Putting all your hopes and dreams for the database (as well as your data integrity rules) is short-sighted.

ORMs有自己的位置,那不是数据库设计。在设计一个数据库时,有很多需要考虑的事项,不管不考虑设计的想法有多吸引人,都需要通过不自动生成来考虑。通常需要考虑许多与应用程序无关的事情,比如数据完整性、报告、审计表和数据导入。使用ORM创建一个看起来像对象模型的数据库,可能不是性能的最佳设计,也可能没有您真正需要的数据完整性。请记住,即使您认为除了应用程序之外什么都不会碰到数据库,这也不是真的。在某些情况下,数据库将需要有人进行主要的数据修改(以修复问题),这些修改是直接在数据库上完成的,而不是通过应用程序完成的。在某一时刻,您需要从刚刚购买的其他公司中导入100万份记录,并在teh应用程序之外需要一个ETL流程。将您对数据库(以及您的数据完整性规则)的所有希望和梦想放在一起是短视的。