I second Griff, specifically you have to define default values in the MSSQL table. If there are no defaults defined and a field is nullable null is taken as value, unlike VFP tables, where a missing default value is filled with a data type spcific empty value and you explicitly need to set default to NULL.
But actually, MSSQL is ANSI compliant with that behavior and VFP is not.
But - again but - VFP does not fill in NULLs, just try this without any Foxpro involvement in MS SQL Management studio:
Code:
INSERT INTO table (column1, column2,..., column5) VALUES (1, 2, ..., 5)
You'll see the other columns become NULL, also if nothing is specified for them.
So it's not VFP forcing in NULLs, it's the columns nullability that does that.
Same goes for MySQL, this is the standard of SQL. If you want some column to have a default value, you have to set that in the table definition. If you set a column not nullable and specify no default value it becomes even worse and INSERT statements without specifying values for the columns fail, because still NULL is tried to be inserted even though the SQL engine knows these columns can't be null and could use empty strings for many character data types and 0 for numeric data types, FALSE for bit fields and so on, but then it stops to have a logical value for date or datetimes, there is no empty date/datetime in any database besides VFP.
And the rest of the datasbase world here has the normal and logical concept about missing values, that is the meaning of NULL.
In essence, your two options are 1. to define default values in the table definition or 2. to specify them specifically in the insert statement. Whether to disallow null in the columns is a separate decision, as it doesn't only depend on whether a record only optionally has a value in those columns at the initial "birth" state of the life cycle of such a record, but also whether that columns can become null later,w whether that attribute can be purged without deleting the whole record.
So, you can have any combination of nullable and non-nullable fields with or without a default value. A bit off topic, as your columns obviously are nullable: Non-nullable fields without default values obviously are forcing clients to specify all values and are the least comfortable, so you're a bit luckier. But it's also a valid concept, it makes all such fields mandatory and if they are it would be an error to allow nulls and if there is no sensible default it also would be an error to define one just to prevent errors. If you have legitimate demands you have legitimate demands of clients to specify all columns values.
The combinations you can do are not designed to guarantee error-free table usage.
Ok, enough food for thought, I think. But if you're accusing VFP to force in NULLs you're barking up the wrong tree, you can turn on SQL PRofile and see for yourself what statements arrive. It's SQL Server who fills in the NULLs for unmentioned columnns when they have no default.
A simple examplem fully MSSQL contained without any Foxpro influence:
Code:
Declare @testtable as table (id int identity(1,1), somecolumn char(10) not null, othercolumn char(10) null)
Insert into @testtable (somecolumn) values ('Hello') -- works and inserts 'Hello' into somecolumn and nothing into othercolumn, which is NULL, therefore.
Select * from @testtable
Insert into @testtable (othercolumn) values ('World') -- errors as soomecolumn isn't nullable (not null) and so some value has to be specified
Select * from @testtable -- shows the table therefore is unchanged and only has the first record
Bye, Olaf.
Olaf Doschke Software Engineering