Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are created and modified the two fields every database table should have?

Tags:

database

rdbms

I recently realized that I add some form of row creation timestamp and possibly a "updated on" field to most of my tables. Suddenly I started thinking that perhaps every table in the database should have a created and modified field that are set in the model behind the scenes.

Does this sound correct? Are there any types of high-load tables (like sessions) or massive sized tables that this wouldn't be a good idea for?

like image 379
Xeoncross Avatar asked Sep 04 '10 03:09

Xeoncross


People also ask

What are the two views you can use to create a table in access?

The two most important views are: Datasheet View allows you to enter information into your database. It is in a table format similar to Excel. Design View allows you to setup and edit the fields of your database.

What is the field in a database table?

1) In a database table, a field is a data structure for a single piece of data. Fields are organized into records, which contain all the information within the table relevant to a specific entity.

How many fields should a database have?

There is no constraint on number of fields in database theory. A table can be limited to a primary key (even if this primary key is made of 2 fields), meaning that Apocalisp's answer is not very clear. At the opposit, a table can be made out of thousends of fields, as long as normal form rules are respected.

Why are field created in a database?

When you create a database table, you first define the fields to determine the kinds of data that can be stored in the table. Each database table has fields, or containers to hold the data, and rows of data, which are also called records. The fields should be defined to determine what kind of data they can contain.


2 Answers

I wouldn't put those fields (which I generally call audit fields) on every database table. If it's a low-traffic, high-value table (like Users, for instance), it goes on, no question. I'd also add creator and modifier. If it's a table that gets hit a lot (an operation history table, say), then maybe the benefit isn't worth the cost of increased insert time and storage space.

It's a call you'll need to make separately for each table.

like image 134
Michael Petrotta Avatar answered Sep 28 '22 02:09

Michael Petrotta


Obviously, there isn't a single rule.

Most of my tables have date-related things, DateCreated, DateModified, and occasionally a Revision to track changes and so on. Do whatever makes sense. Clearly, you can invent cases where it's appropriate and cases where it is not. If you're asking whether you should add them "by default" to most tables, I'd say "probably".

like image 36
Noon Silk Avatar answered Sep 28 '22 01:09

Noon Silk