Posts

Showing posts with the label SQL Server

Find Column in Database - SQL Server

Use the following query to find column in your database. Change “yourdbname” and “%ColumnNameToSearch%” column name accordingly. Use yourdbname 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 c ON t.OBJECT_ID = c.OBJECT_ID WHERE c.name LIKE '%ColumnNameToSearch%' ORDER BY schema_name, table_name; Thanks to Pinaldave .

Find database table column

To find out a column you are not sure of where in your entire database, select database from the dropdown and run following query: SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name = 'COLUMN_NAME'

Rename SQL 2005 Database - Error: The database could not be exclusively locked to perform the operation.

During database restore, I tried to rename existing database in SQL Server 2005 by simply trying following command: ALTER DATABASE mydatabase MODIFY NAME = mydatabase_OLD But it didn't work and gave following error: "The database could not be exclusively locked to perform the operation." In order to fix, I had to set it to single user for a while, change the name and then set it back to multi-user. I had to execute following commands to make it work: ALTER DATABASE mydatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO ALTER DATABASE mydatabase MODIFY NAME = mydatabase_OLD GO ALTER DATABASE mydatabase_OLD SET MULTI_USER GO