[freetds] FreeTDS creating all fields as not null

Eloy Lafuente stronk7 at moodle.org
Thu Sep 21 15:00:11 EDT 2006

Hi Constantin,

I'm not specifying the null clause (because it's supposed 
that, if you don't specify it, the field is NULLable). If 
NULL is specified (like in your example, everything seems to 
work fine).

But this sentence:

create table foo(id int)

seems to work properly from the tsql command line 
interpreter with the field being created as nullable
but, if I execute the same sql statement from PHP (using the 
FreeTDS PHP module), I got the table created with the field
set to NOT NULL.

The exact PHP code I'm using is:

if (!$res = mssql_connect(.....)) {
     error ('bad conn');
mssql_query('create table foo(id int)', $res);

Having the profile enabled at server side I see how the 
sentence arrives (batch starting) and how it's completed. 
The sentence is correct but the generated table has the id
field set to NOT NULL. and this only happens from PHP.

Does this clarify anything? Ciao, Eloy :-)

 > Constantin Vasilyev escribió:
> That doesn't seem to be the case for me.
> [106] MSSQL0.testdb.1> create table foo(id int null);
> [107] MSSQL0.testdb.1> sp_help foo; -mvert | grep Nullable
> Nullable:             yes
> [108] MSSQL0.testdb.1> select @@version;
> Microsoft SQL Server 2005 - 9.00.2047.00 (Intel X86)
>         Apr 14 2006 01:12:25
>         Copyright (c) 1988-2005 Microsoft Corporation
>         Standard Edition on Windows NT 5.2 (Build 3790: Service Pack 1)|
> Would you please provide an example of what you're doing (you may catch
> what's actually comes to the server using Profiler).
> Constantin Vasilyev
> On Thu, 21 Sep 2006, Eloy Lafuente wrote:
>> Hi,
>> I'm using FreeTDS to handle one MSSQL 2005 server with PHP
>> running the "replacement" php_mssql extension with this
>> freetds.conf file:
>> [global]
>>      host =
>>      port = 1433
>>      client charset = UTF-8
>>      tds version = 7.0
>> Everytime I create one table having NULL fields, they become
>> NOT NULL in the target DB.
>> Curiously, executing the same CREATE TABLE statement from
>> the "tsql" command line interface, the table is created
>> properly (with NULL fields being NULL).
>> Any idea about how this could be solved?
>> TIA and ciao, Eloy :-)
>> _______________________________________________
>> FreeTDS mailing list
>> FreeTDS at lists.ibiblio.org
>> http://lists.ibiblio.org/mailman/listinfo/freetds

More information about the FreeTDS mailing list