:::: MENU ::::

Usefull T-SQL functions for using in scripts

  • Aug 06 / 2008
  • 0
DBA Interview questions, dbDigger, System Functions

Usefull T-SQL functions for using in scripts

Here are some use full T-SQL functions which may be help full during several operations.

--Change comptibility level of DB
EXEC sp_dbcmptlevel AdventureWorks, 90  
GO

--To get Name of SQL Server instance
SELECT @@SERVERNAME  
GO

-- To get name of sql server service
SELECT @@SERVICENAME  
GO

-- To get info about logged in user
SELECT @@SPID AS 'ID', SYSTEM_USER AS 'Login Name', USER AS 'User Name'  
GO

--Check disk allocation for a database
DBCC CHECKALLOC  
GO

--Check number of connections/attempted connections since sql server started
select @@CONNECTIONS  
GO

--Display info about a db
sp_helpdb pubs  
GO

-- Display info about a table
sp_help tablename  
GO

--get list of all user databases
sp_databases  
GO

-- To Get Name of ur current working DB
select db_name()  
GO

--Retreive character map
exec sp_helpsort  
GO

These are all building blocks and will help you to get valuable information while creating triggers, logs, SPs etc.

Consult us to explore the Databases. Contact us