SQLTeam.com | Weblogs | Forums

Host_Name() in column default value not correctly value


#1

Hi all
when i use SELECT HOST_NAME() in query editor the result is the host name of client this is true result

but when i put HOST_NAME() as default value of column the result value i server name not client this is false value
i want client host name not server host name in default value of column

thanks all


#2

How and Where do you execute the Query to insert the record into the table ?


#3

column default value in design

ALTER TABLE cdc.dbo_ERP_Taxs_CT ADD CONSTRAINT
	DF_dbo_ERP_Taxs_CT_UserHostName DEFAULT Host_Name() FOR UserHostName

#4

i mean where is the client application excute ? Is it on the same machine as the SQL Server ? or a separate PC ?

Try perform a INSERT to the table in the Query Window. Does it also show the correct host name ?


#5

from my machine
open SQL Server 2014 Management Studio
connect to other PC having my database

open new query in my database
execute SELECT HOST_NAME()
the result is MALI [my pc name]

in the same session open my table and insert new row manual . the result of default value of my column is ERPSERVER [server name having my database]


#6

is there any trigger on that table ? Check the trigger


#7

Thanks Khatn.
There is no trigger, the problem was in CDC system.
the default value of column in CDC table that execute the even from server not client server.
when i try to do host_name in default column in my table not CDC table it works fine
Note: CDC = Change Data Capture.
thanks you.