I was wondering if there is any way to make a single Not Null constraint that could apply to all the attributes in my table. I know I could add one to each line, but I am just trying to learn to be more efficient. I tried searching online and I didn’t find anything on this topic.
Thanks!
MORE INFO:
I guess my question could be generalized to ask “Is there any way to define table-wide or database-wide constraints?”. For this entire database, I need to the default value of every varchar to ” (the empty string) but right now I am doing that manually for every varchar.
Again, I already did most of it, but it seems like there should be a way to avoid this repetition.
From http://dev.mysql.com/doc/refman/5.1/en/create-table.html – the only place you can put a null/not null is on a column.
There’s really no reason to have a table constraint, IMO. The DDL specifies constrains on the data in each column, not the column definition itself. While one might want to put this in as syntactic sugar, it seems like there could be disadvantages – 1) to add a new column you might have to alter the table constraint 2) MySQL defaults to NULL and this might lead to confusion