How to Find the Database Name from the Backup file

June 29, 2012

To find the Database Name from the backup file (bak) we can use the following query:

RESTORE HEADERONLY FROM DISK = 'C:\AdventureWorks.BAK'
GO

The above query will return the content of the SQL Server backup as well.

For the syntax please see here http://msdn.microsoft.com/en-us/library/ms178536.aspx

Advertisements

SQL Query to find the column name in all the tables in a database

June 28, 2012

The below query will display the list of all the tables with same column name:

USE <DatabaseBase>
GO
SELECT T.name AS Table_Name,
SCHEMA_NAME(schema_id) AS Schema_Name,
C.name AS Column_Name
FROM sys.tables AS T
INNER JOIN sys.columns AS C ON T.OBJECT_ID = C.OBJECT_ID
WHERE C.name LIKE ‘%<ColumnName>%’
ORDER BY schema_name, Table_Name;


Grant all the stored procedures to a User

June 27, 2012

To Grant the permission for all the stored procedures to a User we can use the following command:

USE <DatabaseName>
GO
GRANT EXECUTE to <User>;
GO

 


%d bloggers like this: