Monday, September 30, 2013

List All columns of a Table with their data type

USE AdventureWorks2008
GO 
SELECT t.name, 
t1.name,
t.name,
t1.name,
c.name,
c.max_length,
c.precision,
c.collation_name
FROM sys.TABLES t JOIN sys.COLUMNS c ON t.object_id = c.object_id JOIN sys.types t1 
ON c.user_type_id = t1.user_type_id WHERE t.name = 'Employee'
 

How to check the installed version of powershell

 

The Easy Way, in the powershell prompt type:

PS D:\> $host.Version

Major  Minor  Build  Revision
-----  -----  -----  ------
2      0      -1     -1

Wednesday, August 21, 2013

system_health session incidentally dropped

The session can be recreated using the file u_tables.sql (the script is at the bottom of the file) that is located in :

C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\Install\

Wednesday, August 7, 2013

List disabled Jobs and their schedule


To List the disabled Jobs and their relative schedules , you can run the following query:

USE msdb
GO
SELECT
 ss.schedule_id ,
 J.name,
 ss.name,
 J.enabled [Job Enabled ?],
 ss.enabled [Schedule ENABLED ?]
FROM sysjobs J
JOIN sysjobschedules s
 ON J.job_id = s.job_id
JOIN sysschedules ss
 ON s.schedule_id = ss.schedule_id
WHERE J.enabled = 0

The schedule_id can be used directly with sp_update_schedule, as from SQL 2008 schedules can be managed independantly of jobs.

Thursday, July 11, 2013

List all tables with their schema name in a database

SELECT T.name ,S.name 
FROM sys.tables T JOIN sys.schemas S ON T.schema_id = S.schema_id              
ORDER BY T.name ASC