If i understand correctly "NOT NULL" when used it for any data that can be written at the point of table creation, and if there are colunm data which are required but to be written after table creation thy need to be either DEFAULT NULL or NOT NULL DEFAULT 'xxx'?
Usecase is the session table. The row is written when the user logs in. So at that point we write the date, IP, session id, member id, etc. But when the user logs off then i need to write the end datetime, the last page he was on, mode of log off, etc.
So for these end colunms if i use NOT NULL there will be no value to write at row creation time. Am i correct or am开发者_运维知识库 i missing something on how data is written?
You could use a default value or you could move the end date to a new table so that it doesn't have to be populated at the same time as start date. As a rule, either of those two options would be preferable to having a null date.
If you set those end columns as NOT NULLs, the database will throw you an exception when you are trying to write data upon user login. Setting a column as NOT NULL means they must not be NULL when insert a new row. In your case, you want to make the end columns (end datetime, last page, etc) to be nullable whereas you make columns like date, IP, session ID, member Id to be NOT NULLs.
精彩评论