column-defaults

Should a database table have default values?

二次信任 提交于 2019-12-22 03:23:05
问题 I was having a discussion with a developer at work on the issue of should a table use default values. Is there a hard and fast rule on this or is it a gray area in best practices? 回答1: My rule: if many records will use that default (at least initially) then I like to use it as a default. For example, an image table for products in an online store might have a default path of images/NoPictureYet.png . Eventually, those will get replaced, but for batch loads of data where the pictures simply

FluentNHibernate - Setting default value for DB columns (SQL Server)

蹲街弑〆低调 提交于 2019-12-21 04:46:17
问题 does anyone know a way how I could set through mapping the default value of a column so for e.g. when I generate DB from mappings I would have DateTime column having getdate() as default value? I tried so far this (looks exactlly like what I need) but it doesn't work this.Map(x => x.LastPersistedOn, "DateModified") .Access.Property() .Default("getdate()"); 回答1: I just tried setting some default values and it worked as expected. I am using Fluent as retrieve from Git the 24.05.2010 so updating

INSERT …RETURNING .. comes up empty when BEFORE trigger cancels statement

寵の児 提交于 2019-12-11 02:27:00
问题 I have a PostgreSQL before insert trigger on create that basically redirects inserts into sub-tables. Once I insert the record, I want to ABORT the request as to avoid duplicate data (by not inserting into parent table) so I am using return NULL in the trigger. The problem is that I need the record to be returned so I can get the ID. If I return NULL, I get NULL. The above problem is discussed at below link: PostgreSQL trigger not returning anything One of the answers says to insert into

Should a database table have default values?

寵の児 提交于 2019-12-04 23:33:49
I was having a discussion with a developer at work on the issue of should a table use default values. Is there a hard and fast rule on this or is it a gray area in best practices? My rule: if many records will use that default (at least initially) then I like to use it as a default. For example, an image table for products in an online store might have a default path of images/NoPictureYet.png . Eventually, those will get replaced, but for batch loads of data where the pictures simply don't exist yet (and maybe most of them never will!), a default makes sense (to me, at least). If there is no