database-design

Use of empty strings instead of null - a good practice?

时间秒杀一切 提交于 2019-12-23 16:07:28
问题 Consider for example in the database: CREATE TABLE users ( id INTEGER IDENTITY PRIMARY KEY, last_name VARCHAR (50) DEFAULT '' NOT NULL, first_name VARCHAR (50) DEFAULT '' NOT NULL, email VARCHAR(50) DEFAULT '' NOT NULL) And consider a program that interacts with this database using Hibernate as ORM. In my opinion this would mean: avoiding NullPointerExceptions avoiding the need to check for null values Is this good practice? Please give examples of the pros and cons. 回答1: As PeterMmm writes,

Database design 1 to 1 relationship

不想你离开。 提交于 2019-12-23 15:58:20
问题 I design my database incorrectly, should I fix this while its in development? "user" table is suppose to have a 1.1 relationship with "userprofile" table however the actual design the "user" table has a 1.* relationship with "userprofile" table. Everything works! but should it be fixed anyways? 回答1: Do one thing User Table Userid(p) UserName othercol.. UserProfile id(p) UserId(f) - and unique othercol.. hope this way you can easily fix the isse 回答2: Make the user_id in the user_profile table

Modeling products with vastly different sets of needed-to-know information and linking them to lineitems?

醉酒当歌 提交于 2019-12-23 15:07:59
问题 I'm currently working on a site that sells products of varying types that are custom manufactured. I've got your general, standard cart schema: Order has many LineItems, LineItems have one Product, but I've run into a bit of a sticking point: Lets say one of our products is a ball, and one of our products is a box of crayons. While people are creating their order, we end up creating items that could be represented by some psuedocode: Ball: attributes: diameter: decimal color: foreign_ref_to

Dealing with “hypernormalized” data

隐身守侯 提交于 2019-12-23 12:45:51
问题 My employer, a small office supply company, is switching suppliers and I am looking through their electronic content to come up with a robust database schema; our previous schema was pretty much just thrown together without any thought at all, and it's pretty much led to an unbearable data model with corrupt, inconsistent information. The new supplier's data is much better than the old one's, but their data is what I would call hypernormalized . For example, their product category structure

Why is it necessary to indicate identifying or non-identifying relationships in an ERD?

拈花ヽ惹草 提交于 2019-12-23 12:44:01
问题 In an ERD, a weak/non-identifying relationship is one that connects two strong entities, and is indicated with a dashed line. A strong/identifying relationship is one that connects a strong entity to a weak entity (a weak entity is one that contains the foreign key [FK] from its related entity as a component of its own primary key [PK]), and is indicated by a solid line. My question is, So what? Why is it so important to distinguish between weak/non-identifying relationships versus strong

Database tables, one table referencing multiple unrelated tables

让人想犯罪 __ 提交于 2019-12-23 11:59:48
问题 This question has come up a few times in various forums in my searching, but none have provided a concise resolution. If I have the following tables: User +- id +- username +- password Article +- id +- title +- content and I want to join them in order to determine who created what articles, I could simply add the column user_id to Article to use as a reference. Alternatively, I'm adding an intermediate table to show who/when/what, for example: User +- ... Article +- ... ChangeHistory +- id +-

InnoDB or MyISAM - Why not both?

你离开我真会死。 提交于 2019-12-23 11:55:06
问题 I've read various threads about which is better between InnoDB and MyISAM . It seems that the debates are to use or the other. Is it not possible to use both, depending on the table? What would be the disadvantages in doing this? As far as I can tell, the engine can be set during the CREATE TABLE command. Therefore, certain tables which are often read can be set to MyISAM, but tables that need transaction support can use InnoDB. 回答1: You can have both MyISAM and InnoDB tables in the same

Data driven business rules.

半腔热情 提交于 2019-12-23 10:27:10
问题 I am using SQL SERVER 2005. I have a table table1(ID,col1,col2,col3,col4); Now I have a business logic like: If col1 >= 126 and col2 > 1 then col3 = 0 if col1 >=126 and col2 < 1 then col3 = col1+col4 Now what I am trying to do is store all these rules in database and make it data driven. THe reason for that is to give the end user more flexibility. If tomorrow the business rules changes, end user have the flexibility to change it through the GUI. For eg. if tomorrow the business wants to

database refinement - minimal cover of F (extraneous attributes)

夙愿已清 提交于 2019-12-23 10:21:37
问题 Schema R = (A, B, C, D, E, F) FD F = {ABC -> D, CD -> B, BCF -> D, CDF -> BE, BCDF -> E} Find Fc, the minimal cover (aka. canonical cover) of F. This is the method using in my book: Example: abc -> xyz a is redundant (extraneous) if (bc)+ ⊇ a; x is redundant if (abc)+ ⊇ x. NOTE: Here, the closures are computed using F, with a or x being deleted from abc -> xyz respectively. I don't understand the last bold sentence. one solution is: Consider CDF -> BE B is redundant: (CDF)+ = (CDFBE) ⊇ ( B )

Select * sql query vs Select specific columns sql query [duplicate]

时光总嘲笑我的痴心妄想 提交于 2019-12-23 09:58:27
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Why is SELECT * considered harmful? Probably a database nOOb question. Our application has a table like the following TABLE WF Field | Type | Null | Key | Default | Extra | +--------------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | children | text | YES | | NULL | | | w_id | int(11) | YES | | NULL | | | f_id | int(11) | YES | | NULL | | |