Applies To: SQL Server 2014, SQL Server 2016 Preview
Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to existing features in Microsoft SQL Server 2016 Community Technology Preview 2 (CTP2).
Returns the workstation name.
Applies to: SQL Server (SQL Server 2008 through current version).
When the parameter to a system function is optional, the current database, host computer, server user, or database user is assumed. Built-in functions must always be followed by parentheses.
System functions can be used in the select list, in the WHERE clause, and anywhere an expression is allowed.
The client application provides the workstation name and can provide inaccurate data. Do not rely upon HOST_NAME as a security feature.
The following example creates a table that uses HOST_NAME() in a DEFAULT definition to record the workstation name of computers that insert rows into a table recording orders.
CREATE TABLE Orders (OrderID int PRIMARY KEY, CustomerID nchar(5) REFERENCES Customers(CustomerID), Workstation nchar(30) NOT NULL DEFAULT HOST_NAME(), OrderDate datetime NOT NULL, ShipDate datetime NULL, ShipperID int NULL REFERENCES Shippers(ShipperID)); GO