Click to Rate and Give Feedback
TechNet
TechNet Library
SQL Server
SQL Server 2005
 HOST_NAME (Transact-SQL)
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
SQL Server 2005 Books Online (November 2008)
HOST_NAME (Transact-SQL)

Returns the workstation name.

Topic link icon 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.

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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker