How do I list all the indexes on a particular table in sqlserver 2005?
GO
EXEC sp_helpindex 'Your_Table_Name'
GO
How do we list all the statistics for particular table?
GO
EXEC sp_helpstats 'YOUR_Table_Name'
GO
CREATE FUNCTION GetEmpName
(
-- Add the parameters for the function here
@EmployeeId int
)
RETURNS NVARCHAR(100)
AS
BEGIN
-- Declare the return variable here
DECLARE @empname NVARCHAR(100)
SELECT @empname = LastName +', ' + FirstName FROM Employees WHERE EmployeeID=@EmployeeId
RETURN @empname
END
GO
SELECT distinct dbo.GetEmpName(a.EmployeeID), b.TerritoryDescription
FROM dbo.EmployeeTerritories a
INNER JOIN dbo.Territories b
ON a.TerritoryID=b.TerritoryID
WHERE dbo.GetEmpName(a.EmployeeID)='Davolio, Nancy'
CREATE FUNCTION dbo.GetEmpNameCrossJoin
(
-- Add the parameters for the function here
@EmpId int
)
RETURNS Table
AS
Return(
SELECT LastName + ', ' + FirstName EName FROM dbo.Employees)
GO
--Now execute this using Cross APPLY
SELECT distinct I.EName, b.TerritoryDescription
FROM dbo.EmployeeTerritories a
INNER JOIN dbo.Territories b
ON a.TerritoryID=b.TerritoryID
CROSS APPLY dbo.GetEmpNameCrossJoin(a.EmployeeID) I