GreenEyed wrote:Good database practice says that null is not yes or no, it is simply null, so it should not be used as a value but as "absence of value".
If it is mandatory to have a value, then you specify "not null", but one might need the possibility to be able to set it to null, as a way of saying "not decided, yet". So, IMHO, setting it always to "not null" is not a good rule of a thumb.
I don't understand the part about not needing to use an update query to change the value when using 0/1 as flag. How would you do that? I have no experience with mySQL so I'm curious to learn new ways of doing things .
I read somewhere on mysql.com that if a field is decalared as 'int not null' that the database would work faster than when it just 'int' with some of the values in table =NULL.
my previous statement was actually correct only regardsing jforum, where
initial value is NULL and write to the database makes it 0/1
for example src/net/jforum/dao/generic/GenericUserDAO.java
public void setActive(int userId, boolean active) throws Exception
{
PreparedStatement p = JForum.getConnection().prepareStatement(SystemGlobals.getSql("UserModel.activeStatus"));
p.setInt(1, active ? 1 : 0);
p.setInt(2, userId);
p.executeUpdate();
p.close();
}
so a query
SELECT * from jfroum_user WHERE user_active;
would work ok if a field is declaration would be changed to INT NOT NULL (the defauld will be 0).
[originally posted on jforum.net by Anonymous]