Database Design for Custom Fields

  Рет қаралды 28,579

Database Star

Database Star

Күн бұрын

Пікірлер: 63
@DatabaseStar
@DatabaseStar 10 күн бұрын
Want to improve your database design skills? Get my Database Design project Guides here (diagrams, explanations, and SQL scripts): www.databasestar.com/dbdesign/?
@marna_li
@marna_li 3 жыл бұрын
In my project, I added a CustomFieldDefinitions table and a CustomFields table, for the Orders table. My idea was to get a clean structure. It was proven to be bad when I tried to implement filtering of Orders and thus wanted CustomFields to be included. I used Entity Framework and the idea was compile a structured query string arg into a query. But you cannot flatten all custom fields per Order to columns that the ORM can handle. My next attempt will be with a JSON field.
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Thanks for sharing. Sometimes designs can work at one point but later on they can be hard to work with.
@rikyriky966
@rikyriky966 3 жыл бұрын
I prefer 3NF Normalized Tables (6th in the video) and the JSON (7th) for my large scale app’s database design. Thanks for the video. :)
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Awesome, good to hear!
@bugloper
@bugloper Ай бұрын
Data integrity can be maintained by creating a value table for each datatype, storing attribute and value in different tables. But this makes query really complex but can be solved by introducing a flat table, some sort of read model, for single select query
@DatabaseStar
@DatabaseStar Ай бұрын
Yeah I can see how that can work, thanks for sharing.
@jellehuibregtse9476
@jellehuibregtse9476 2 жыл бұрын
Thanks for this video, I really like your clear voice and concise explanations.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
No problem! Glad it was helpful.
@jhfdjdhfdgfghjzrztku
@jhfdjdhfdgfghjzrztku 2 жыл бұрын
JSON support in most major DBMSes has gone a long way, but if your data is highly dynamic to begin with, you are probably bringing a knife to a gun fight and should consider a NoSQL database for your application
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Good point. Using JSON data for custom fields, in a NoSQL database, could be the way to go.
@mr.random8447
@mr.random8447 Жыл бұрын
I need ACID, but also need custom fields. What do I do? Have an id column in SQL that points to a document in MongoDB. Two databases?
@mmaaaxxxxx
@mmaaaxxxxx 3 жыл бұрын
For #3 the video missed the most important con, which is in multi-tenancy, each customer, with a click in the product, would change the basic database schema. That shuts down the solution right there. (if your situation is not multi-tenancy, then you probably don't even need to worry about custom fields) edit: and it's thousands or tens of thousands of columns, not 50-200
@DatabaseStar
@DatabaseStar 3 жыл бұрын
That's a good point, if there are many customers then the number of custom fields would increase a lot. This is something to consider.
@havenlin5633
@havenlin5633 3 жыл бұрын
I would prefer #1 EAV, and #7 JSON for alternative, thanks for sharing.
@mr.random8447
@mr.random8447 Жыл бұрын
EAV bad, you chose the worse options. Best is Normalized
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks for sharing!
@DatabaseStar
@DatabaseStar Жыл бұрын
Yeah generally normalised is better
@FLAWLESSBEATS
@FLAWLESSBEATS 11 ай бұрын
@@DatabaseStar What if you need to create custom attributes for a certain class in your application? Normalized option obligates you modify your app to create a new class and a new table on the database in order to have a new type of attribute, so in that case using sort of an EAV solution is better right?
@aubbusta
@aubbusta 2 жыл бұрын
Json is the best solution for a dynamic fields even big companies use it on their api
@DatabaseStar
@DatabaseStar 2 жыл бұрын
That’s a good point!
@be_real_truth_matters
@be_real_truth_matters Жыл бұрын
Magento cms indexing mechanism solves entity attribute value performance...that can also be applied to worpdress to solve performance issue...I think nosql can be used with sql to indexing the large public data, for eg: ecommerce product data & confidential records like order, stocks can be stored in sql for better secured storing...
@DatabaseStar
@DatabaseStar Жыл бұрын
That's a good point, good to see it can help for those systems.
@taamcyat
@taamcyat Жыл бұрын
I've had much success with EAV using: * (1) MSSQL and the Variant type so that you only have 1 value table(or column). * (2) use strongly typed and optimized hand written SQL stored procedures(middle-tiered ORM generated SQL is not always a good idea for reporting queries). * (3) Create a dynamic-PIVOT operation stored procedure to generate a pivoted 'flat' table for reporting. Legally inject parameters(list of required attributes) from the reporting user interrace into the dynamic(sql) PIVOT stored procedure to generate the pivoted flat table. I used COUNT and /or MAX as the PIVOT aggregate function. * (4) Use optimized indices(indexes). You actually can index the tables easily. Also you don't really need to cast or convert values since the very nature of the query would limit the types (attributes) required and also that you are using the Variant data type that is directly sent straight up to the user interface reporting visualization elements. These alone solved my issues. I seeded the model(the value table) with millions of records and the performance is amazingly fast! As a bonus, you can further 'cube' the generated pivoted flat table to generate further summaries and statistics before presentation.
@DatabaseStar
@DatabaseStar Жыл бұрын
Great tip! That approach sounds good and it's good to hear it works for you.
@CallMe_PsPsPs
@CallMe_PsPsPs 3 жыл бұрын
Working with norlamized (#6) all time. Json sometimes too (#7) but now I have to switch my articles to EAV.
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks for sharing, good to know!
@alankalbfleisch3141
@alankalbfleisch3141 8 ай бұрын
I think the Modified EAV could be modified even more to be a bit more useful. Instead of a single customer_attributes table, why not three tables for the different data types (customer_string_attribute, customer_date_attribute, customer_number_attribute). This allows for better data validation compared to EAV and removes the risk of multiple columns being populated. It does add more complexity when trying to query all attributes.
@DatabaseStar
@DatabaseStar 8 ай бұрын
Good point! I think that can work as well.
@saran-ravi
@saran-ravi 2 жыл бұрын
Great video
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks!
@kushagrajain2407
@kushagrajain2407 2 жыл бұрын
@DatabaseStar This is a bit difficult to understand without any table examples of how it looks like. Is there any blogpost where you have explained it with an example. thanks in advance :)
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks for the feedback! Yeah I've heard that before about this video and some others, so I try to add examples into some of my recent videos. I don't have any posts that has examples unfortunately - but I can create one in the future.
@martinjones8237
@martinjones8237 2 жыл бұрын
Nice video! Anybody know what "PK" and "RK" refers to in these diagrams? This is the only thing I'm missing!
@vivekbansal7207
@vivekbansal7207 2 жыл бұрын
primary key
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Ah, PK = Primary Key (the unique identifier for the row), and FK = Foreign Key (a reference to a Primary Key in another table)
@ADAMSIVES
@ADAMSIVES 3 жыл бұрын
Very helpful for me
@DatabaseStar
@DatabaseStar Жыл бұрын
That’s great!
@ADAMSIVES
@ADAMSIVES 3 жыл бұрын
I didn't think of the JSON (or potentially XML??? - is that a thing too?) version until you said it....
@DatabaseStar
@DatabaseStar Жыл бұрын
Good to know! Yeah XML could work but I don't see it used very often.
@ZachariBarnes
@ZachariBarnes Жыл бұрын
Only a few of these options support custom fields and none of these support defining a custom field(column) (which would be different for each tenant) to which each row would have a value.
@DatabaseStar
@DatabaseStar Жыл бұрын
What do you mean by "only a few support custom fields"? And what do you mean by "none of these support defining a custom field"? Each of them allow users to define custom fields, where the users can determine what information can be captured for a record. If there's a need to have a new column where each row has a value, then this would be more like adding a new column to a table, and would be done with an Alter Table statement.
@hassamulhaq7762
@hassamulhaq7762 2 жыл бұрын
Dynamic Design looks 😬 due to risk of columns change on live server. need strong validation for this type. I prefer JSON, EAV structure.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks! Yeah there are some risks for this approach.
@mickinoz2005
@mickinoz2005 Жыл бұрын
While I enjoyed the video I am none the wiser as to which is best or better maybe a list of don't do to best option might be good
@DatabaseStar
@DatabaseStar Жыл бұрын
Good idea, thanks for the feedback.
@mouaad_games8
@mouaad_games8 Жыл бұрын
Or just use no-sql DB
@DatabaseStar
@DatabaseStar Жыл бұрын
Yeah that is an option!
@faisalmushtaq2287
@faisalmushtaq2287 4 ай бұрын
i think 1st solution was much better
@DatabaseStar
@DatabaseStar 4 ай бұрын
Oh thanks, that’s good to know
@faisalmushtaq2287
@faisalmushtaq2287 4 ай бұрын
@@DatabaseStar currently watching your "7 database design mistakes to avoid" video👍
@gauravsrivastava17
@gauravsrivastava17 6 ай бұрын
Normalisation
@DatabaseStar
@DatabaseStar 5 ай бұрын
Yeah that is one approach
@ms77grz
@ms77grz Жыл бұрын
👍👍
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks!
@antoniocs8873
@antoniocs8873 3 жыл бұрын
I think you oversimplified the EAV by A LOT.
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Yeah I did simplify it for the video, it can get out of hand pretty easily. What else would you add for EAV?
@antoniocs8873
@antoniocs8873 3 жыл бұрын
@@DatabaseStar Take some notes from this video: kzbin.info/www/bejne/jZ_IeYeIj7uVm8U
Database Design: Product Attributes
4:28
Database Star
Рет қаралды 46 М.
7 Database Design Mistakes to Avoid (With Solutions)
11:29
Database Star
Рет қаралды 87 М.
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
СКОЛЬКО ПАЛЬЦЕВ ТУТ?
00:16
Masomka
Рет қаралды 3,4 МЛН
Ice Cream or Surprise Trip Around the World?
00:31
Hungry FAM
Рет қаралды 22 МЛН
1, 2, 3, 4, 5, 6, 7, 8, 9 🙈⚽️
00:46
Celine Dept
Рет қаралды 114 МЛН
Database Design for School Students for an Entire School
18:34
Database Star
Рет қаралды 28 М.
Laravel DB Custom Fields with EAV-Model: Worth It?
9:11
Laravel Daily
Рет қаралды 24 М.
I loaded 100,000,000 rows into MySQL (fast)
18:27
PlanetScale
Рет қаралды 180 М.
Microservices with Databases can be challenging...
20:52
Software Developer Diaries
Рет қаралды 95 М.
The Birth of SQL & the Relational Database
20:08
Asianometry
Рет қаралды 206 М.
How to Design a Database
10:57
Database Star
Рет қаралды 70 М.
Laravel Custom Fields: JSON, EAV, or Add Columns Manually?
5:05
Laravel Daily
Рет қаралды 14 М.
Database Design for Real Estate Company
16:02
Database Star
Рет қаралды 7 М.
Example 1: Transforming ER Diagrams to a Relational Schema
21:48
OrangeOutputs
Рет қаралды 446 М.
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН