Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server 2016 (13.x) and later
Azure SQL Database
Azure SQL Managed Instance
Returns the workstation name.
Transact-SQL syntax conventions
HOST_NAME ()
nvarchar(128)
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.
Important
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
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today