Microsoft® SQL Server™ has built-in functions to perform certain operations quickly and easily. The function categories are:
Functions can be used or included in:
SELECT DB_NAME()
SELECT *
FROM [Order Details]
WHERE Quantity =
(SELECT MAX(Quantity) FROM [Order Details])
CREATE VIEW ShowMyEmploymentInfo AS
SELECT * FROM Employees
WHERE EmployeeID = SUSER_SID()
GO
CREATE TABLE SalesContacts
(SalesRepID INT PRIMARY KEY CHECK (SalesRepID = SUSER_SID() ),
ContactName VARCHAR(50) NULL,
ContactPhone VARCHAR(13) NULL)
CREATE TABLE SalesContacts
(
SalesRepID INT PRIMARY KEY CHECK (SalesRepID = SUSER_SID() ),
ContactName VARCHAR(50) NULL,
ContactPhone VARCHAR(13) NULL,
WhenCreated DATETIME DEFAULT GETDATE(),
Creator INT DEFAULT SUSER_SID()
)
GO
Functions are always used with parentheses, even when there is no parameter. An exception to this are the niladic functions (functions that take no parameters) used with the DEFAULT keyword. For more information about the DEFAULT keyword, see ALTER TABLE and CREATE TABLE, or Defaults.
The parameters to specify a database, computer, login, or database user are sometimes optional. If they are not specified, they default to the current database, host computer, login, or database user.
Functions can be nested (one function used inside another function).