Problems with user_name()

Problems with user_name()

Post by Mitch Mille » Fri, 14 Apr 2000 04:00:00



Just converted from SQL Server 6.5 to 7.0.  Only had one problem ... In many
tables, I create CreatedOn and CreatedBy columns that are bound to defaults
that set the date/time and userId (respectively) when a new row is inserted
into the table.  The default for CreatedBy is user_name().  However, when I
migrated this database, it converted the defaults to user_name(null).  For
some reason, this returns null, rather than the actual user Id.  Since this
column is set to NOT NULL, we had a number of entries that failed to insert.

Why does user_name(null) fail, and user_name() does not?

-- Mitch

 
 
 

Problems with user_name()

Post by Neil Pik » Sat, 15 Apr 2000 04:00:00


Mitch - because the function does not expect a value - this is a problem with
the scripting tool.  Did you migrate using the upgrade wizard or "manually"
with DTS/scripting etc.

 Neil Pike MVP/MCSE.  Protech Computing Ltd
 (Please reply only to newsgroups)
 SQL FAQ (428 entries) see
 forumsb.compuserve.com/vlforums/UK/default.asp?SRV=MSDevApps (sqlfaq.zip - L7
- SQL Public)
 or www.ntfaq.com/sql.html
 or www.sql-server.co.uk
 or www.mssqlserver.com/faq

 
 
 

1. Problem: user_name() as column default

I'm sure someone else has had this problem, but I have not seen any
reference to it.  Basically, the problem I am having is when
designing/modifying a SQL server table in which I have a column using the
function user_name() as a default.  Whenever I reopen the table for
modification, VS changes the default to user_name(null) and if I resave the
table this new default is now used.

However, user_name() and user_name(null) produces different results in the
saved column of the record. User_name() saves the current user's name (ie.
bhayman), but user_name(null) saves the value <null>.

Does anyone know of a fix/workaround to this?  It is getting to be very
annoying.

Thanks,

Bryan E. Hayman

2. Distributor on Subscriber?

3. Transfert DB change the default user_name() in user_name(null). Is it a bug?

4. Tape Rotation Scheme/Retirement for 24X7 Backup

5. how to get serial# of current session or OS user_name

6. ODBC LOB-types

7. Application Role and USER_NAME

8. Florida - Oracle/UNIX Project Manager

9. Function or SP to Return User_Name from A Delete Trigger

10. Changes in the User_Name value in SQL 2000

11. USER_NAME() returns NULL

12. user_name function "bug"

13. User_Name() in Access-2000