Database design for database-agnostic applications

后端 未结 17 1744
隐瞒了意图╮
隐瞒了意图╮ 2021-02-02 14:15

What do I have to consider in database design for a new application which should be able to support the most common relational database systems (SQL Server, MyS

相关标签:
17条回答
  • 2021-02-02 14:36

    Keep field and table names short (<30 characters) and case insensitive. e.g. TABLE_NAME and FIELD_NAME

    0 讨论(0)
  • 2021-02-02 14:36

    As well as taking into account the many good and sensible answers here, I'd also add that something like ActiveRecord migrations (from Ruby On Rails, but you can just use the library) might be useful. It abstracts stuff like table creation/alteration, appropriate column types, simpler index management and (to a certain amount) sequencing into a fairly simple descriptive language.

    Stored procedures and triggers are pretty much ignored, but if you're going cross-platform that kind of functionality should probably be in a code layer anyway.

    Out of curiosity I've switched between Oracle, MS SQL, MySQL and SQLite with the same set of migrations and the worst problem I had was discovering I had to ensure my column and table names were not in the union of reserved word lists across the DBs.

    0 讨论(0)
  • 2021-02-02 14:37

    The first thing to consider is if the cost of doing it independent is lower that depend on database. I think some times is important for some products that whant to give choice to customers, but they are loosing a lot of database features (it means code to be written again).

    For big customers (big applications) they have to be fully dependent to database. For little customizes , is reallly a trouble to have an Oracle XE and a MySQL on one server (or two).

    Really, I prefer to use more than one database and that the application knows which database is that an "abastract" code.

    0 讨论(0)
  • 2021-02-02 14:39

    I'm going to plagerize johnstok's answer of 1) Don't use stored procedures and 2) Don't use vendor specific SQL, and add to it.

    You also asked, "Is it even worth the effort?". I'd say... maybe. I wrote a open source bug tracker, BugTracker.NET, that is based on SQL Server. There are many developrs who simply wouldn't give it a try because they like to stick to the technologies they are comfortable with. And, when I was considering starting a hosting service, I noticed that dedicated Linux virtual servers are much cheaper than Windows (non-virtual) services. I could theoretically run the C# under mono, but my SQL is so SQL Server specific (even though I don't use stored procs) it would be a huge effort to port.

    If you are targeting a business/corporate market, you'll find that some shops are strickly Oracle, or strictly SQL Server, and that your app might be ruled out in the early rounds of the competition based on the technology it uses.

    So, maybe being open does matter, to you. What kind of app is it? Who will use it?

    You also asked, "What are the ptifalls". Not testing as you go along. If you plan to support the 4 dbs you listed, then you should be testing with them early and often rather than just target one while thinking it will be easy to convert over to the others. By that time you might find yourself in an architectural cul-de-sac.

    0 讨论(0)
  • 2021-02-02 14:41

    I understand the other answers here but why not use stored procedures? Is it so that the logic is not hidden away?

    0 讨论(0)
  • 2021-02-02 14:43

    One answer people will often tell you is to not use database specific sql and just code to ansi standards. They will often say only talk to the database via stored procs to abstract out any sql. These are the wrong answers and only lead to pain. Coding to 'standard' sql is pretty much impossible because every vendor has such different interpretations.

    What you need to to is have some kind of database persistence layer the abstracts the differences between databases (sorry johnstock, this is almost exactly what you said). There are many other ORMs and similar products to do this for every platform,

    0 讨论(0)
提交回复
热议问题