Wednesday, April 24, 2013

Listing columns in SQL tables

Here is the SQL script to list columns in tables:
 
SELECT
  tab.TABLE_TYPE
, tab.TABLE_NAME
, col.COLUMN_NAME
, DATA_TYPE
, IS_NULLABLE
, CHARACTER_MAXIMUM_LENGTH
FROM
INFORMATION_SCHEMA.TABLES tab
INNER JOIN INFORMATION_SCHEMA.COLUMNS col
ON tab.TABLE_NAME = col.TABLE_NAME
WHERE
tab.TABLE_CATALOG = col.TABLE_CATALOG
AND tab.TABLE_SCHEMA = col.TABLE_SCHEMA
AND COLUMN_NAME like 'COLNAME%'
ORDER
BY
TABLE_TYPE, tab.TABLE_NAME
, COLUMN_NAME

Monday, April 15, 2013

Opereating System returned 5(Access is denied) while attempting to RestoreContainer::ValidateTargetForCreate on

I got the following error while creating a database:

Opereating System returned 5(Access is denied) while attempting to RestoreContainer::ValidateTargetForCreate on

Cause: The user running the MSSQLSERVER service does not have proper access to the path.

Solution: Give proper access to the 'user' running the MSSQLSERVER service.

Saturday, January 19, 2013

SQL Server backups in network location


I had to take backup off-server to a network location. So, created a job tried running manually; it ran just fine. I scheduled the job check during the run time, it fail! Job history
(

  • Expand SQL Server Agent under Instance
  • Expand Jobs
  • Right click the job and choose View History
  • )
    showed the \ did not have permission on the location. Gave the domain user full access to the location, still did not work. I check the user under which the SQL Server (InstanceName) service was running, it was a different domain user; once this domain user had FULL CONTROL to the network location, the job started backing up in a network location specified by UNC.

    Here is a reference: Microsoft Article
    Hope this help someone.

    astu...