Showing posts with label SQL 2005. Show all posts
Showing posts with label SQL 2005. Show all posts

Thursday, August 15, 2013

SQL Server: Query to check if given column exists

 



select  
s.[name] 'Schema',
t.[name] 'Table',
c.[name] 'Column',
d.[name] 'Data Type',
d.[max_length] 'Max Length',
d.[precision] 'Precision',
c.[is_identity] 'Is Id',
c.[is_nullable] 'Is Nullable',
c.[is_computed] 'Is Computed',
d.[is_user_defined] 'Is UserDefined',
t.[modify_date] 'Date Modified',
t.[create_date] 'Date created'
from sys.schemas s
inner join sys.tables t
on s.schema_id = t.schema_id
inner join sys.columns c
on t.object_id = c.object_id
inner join sys.types d
on c.user_type_id = d.user_type_id
where c.name like 'Person%'


Monday, December 03, 2012

The operation cannot be performed on a database with database snapshots or active DBCC replicas

 

When trying to restore the database with snapshots got the following error SQL message

SQL Server T-SQL Command

restore database PRD_Accounts from disk ='H:\PRD_Accounts_backup_daily.bak' with replace, stats

Error:

Msg 5094, Level 16, State 2, Line 1
The operation cannot be performed on a database with database snapshots or active DBCC replicas.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.

Resolution

Since we cannot restore a database if we have any snapshots.
Please drop all snapshots and try database restore again.

1. To check the database snapshot and it’s source database

select database_id, name,source_database_id,Source_DBName=DB_NAME(source_database_id)
from master.sys.databases
where source_database_id IS NOT NULL

2. Drop the Snapshot database

DROP DATABASE Accounts_Rpt


3. Create script of snapshot database, before dropping it. If at all we need to re-establish the snapshot after restore we can use it

USE master
GO

/****** Object:  Database [Benefits_Rpt_sol48u]    Script Date: 12/03/2012 00:01:02 ******/
CREATE DATABASE [Accounts_Rpt] ON
( NAME = N'PRD_Accounts', FILENAME = N'E:\MSSQL\Data\Accounts_Rpt.ss1' ),
( NAME = N'indexdat1', FILENAME = N'E:\MSSQL\Data\Accounts_Rpt.ss2' ) AS SNAPSHOT OF [PRD_Accounts]
GO

Thursday, November 08, 2012

Error on executing sp_cycle_agent_errorlog Msg 22022, Level 16, State 1, Line 0

sp_cycle_agent_errorlog

Every time SQL Server Agent is started, the current SQL Server Agent error log is renamed to SQLAgent.1; SQLAgent.1 becomes SQLAgent.2, SQLAgent.2 becomes SQLAgent.3, and so on. sp_cycle_agent_errorlog enables you to cycle the error log files without stopping and starting the server.

This stored procedure must be run from the msdb database.

Error on executing of sp_cycle_agent_errorlog

clip_image002

image

 

USE msdb

go

EXEC sp_cycle_agent_errorlog

GO

Msg 22022, Level 16, State 1, Line 0

SQLServerAgent Error: Access is denied.

Each time the stored procedure was run it just overwritten the current agent log without renaming it and because of this only one SQLAGENTOUT file was left.

Wednesday, November 07, 2012

SQL Mail: The mail could not be sent to the recipients because of the mail server failure.


SQL Mail Sent fail with errors below;

Error from the SQL Mail log:

The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2012-11-07T22:09:50). Exception Message: Could not connect to mail server. (No connection could be made because the target machine actively refused it 205.191.22.44:25). )

The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2012-01-17T11:13:58). Exception Message: Could not connect to mail server. (No such host is known). )

The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 3 (2012-01-17T11:12:44). Exception Message: Cannot send mails to mail server. (Failure sending mail.). )

The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 1 (2010-10-24T19:55:11). Exception Message: Could not connect to mail server. (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 16.236.32.51:25). )

Resolution:

From the error message it is clear that it is a communication issue between SQL Server host and the Mail Exchange Server.

Problem was related to Exchange Server not allowing relaying from SQL Server.

Please engage Network Administrator to add SQL Server host IP Address to allow to send emails taking below steps, like

On Mail server > Exchange Server Manager > SMTP Connector Properties
> Access Properties > Access Tab > Relay button > Add  IP Address of SQL Server

Also cross check if the Anti Virus (AV) program running on the SQL Server host. AV blocks services from sending on TCP-25. Adjust the AV software accordingly. Add DATABASEMAIL90.EXE to the list of innocent programs in your AV.

Tuesday, November 06, 2012

Query to find the Linked Servers with given remote login

 

It would be useful to cross check, when the Linked Server remote login password has changed.
In this case, linked server will wail due to wrong password. To fix this we have reset the correct password.

SELECT s.server_id,S.name,S.product,S.provider,l.remote_name,'Remote_Login_Modified_Dt'=l.modify_date,s.modify_date
FROM SYS.SERVERS S
INNER JOIN SYS.LINKED_LOGINS L
ON  s.server_id = L.server_id
WHERE S.server_id > 0
AND S.product ='SQL Server'
AND L.remote_name ='sa'

Returning the parameters for a specified stored procedure or function

 

Before you run the following query, replace <database_name> and <schema_name.object_name> with valid names.

USE <database_name>;
GO
SELECT SCHEMA_NAME(schema_id) AS schema_name
    ,o.name AS object_name
    ,o.type_desc
    ,p.parameter_id
    ,p.name AS parameter_name
    ,TYPE_NAME(p.user_type_id) AS parameter_type
    ,p.max_length
    ,p.precision
    ,p.scale
    ,p.is_output
FROM sys.objects AS o
INNER JOIN sys.parameters AS p ON o.object_id = p.object_id
WHERE o.object_id = OBJECT_ID('<schema_name.object_name>')
ORDER BY schema_name, o.object_name, p.parameter_id;
GO

 

Reference: http://msdn.microsoft.com/en-us/library/ms190324.aspx

List database objects modified in the last ‘N’ days

 

Before you run the following query, replace <database_name> and <n_days> with valid values.

 

USE <database_name>;
GO
SELECT name AS object_name
  ,SCHEMA_NAME(schema_id) AS schema_name
  ,type_desc
  ,create_date
  ,modify_date
FROM sys.objects
WHERE modify_date > GETDATE() - <n_days>
ORDER BY modify_date;
GO

 

Source: http://msdn.microsoft.com/en-us/library/ms190324.aspx

Thursday, November 01, 2012

Script to check SQL Server Linked Server Status

 

It leverages on the system stored procedure sys.sp_testlinkedserver


SET NOCOUNT ON;
DECLARE @LinkName NVARCHAR (128), @retval INT, @msg varchar(300)
IF (SELECT COUNT (srvname) FROM sys.sysservers WHERE srvname <> @@SERVERNAME) = 0 RETURN

DECLARE srvname INSENSITIVE CURSOR FOR
        (SELECT srvname FROM sys.sysservers WHERE srvname <> @@SERVERNAME) FOR READ ONLY
OPEN srvname
    FETCH NEXT FROM srvname INTO @LinkName
WHILE @@FETCH_STATUS = 0
BEGIN
    BEGIN TRY
        EXEC @retval = sys.sp_testlinkedserver @LinkName
    END TRY
   
    BEGIN CATCH
        IF @LinkName IS NULL RETURN
        SET @retval = SIGN(@@ERROR)
        IF @retval <> 0
        BEGIN
          SET @msg = 'Unable to connect to the Linked server : ' + @LinkName
          RAISERROR (@msg, 16, 2 )
        END
    END CATCH
    FETCH NEXT FROM srvname INTO @LinkName
   
END   
   
CLOSE srvname
DEALLOCATE srvname

Monday, August 01, 2011

System database msdb size in huge! How to purge MSDB Backup and Restore History?

 

On one of my SQL Server 2008 Instance, the msdb database sizes around 4 GB.  I decided to find out the which table / index occupies major junk on this. I have used query below;

--- Query 1, if there is partition

SELECT TOP 10 SERVERNAME=@@SERVERNAME,DB_NAME=DB_NAME(),TABLE_NAME=OBJECT_NAME(I.ID),INDEX_NAME=I.NAME,INDID,USED, ROWS, SIZE_N_MB = ROUND((USED*8.0/1024.0),2),
ROWMODCTR,STATISTICDT=STATS_DATE(I.ID,INDID)
FROM SYSINDEXES I, SYSOBJECTS O
WHERE I.ID = O.ID
AND INDID IN ( 0,1)
AND XTYPE = 'U'
ORDER BY USED DESC

--- Query 2 If there are partitions

SELECT object_name(i.object_id) as objectName,
i.[name] as indexName,
sum(a.total_pages) as totalPages,
sum(a.used_pages) as usedPages,
sum(a.data_pages) as dataPages,
(sum(a.total_pages) * 8) / 1024 as totalSpaceMB,
(sum(a.used_pages) * 8) / 1024 as usedSpaceMB,
(sum(a.data_pages) * 8) / 1024 as dataSpaceMB
FROM sys.indexes i
INNER JOIN sys.partitions p
ON i.object_id = p.object_id
AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a
ON p.partition_id = a.container_id
GROUP BY i.object_id, i.index_id, i.[name]
ORDER BY sum(a.total_pages) DESC, object_name(i.object_id)

The output resulted;

The following 5 big tables takes up 88% of the total database size of 3.8 GB. These 5 tables occupy 3.3 GB on the msdb database.

Query 1: Output

TABLE_NAME INDEX_NAME INDID USED ROWS SIZE_N_MB ROWMODCTR STATISTICDT
backupfile PK__backupfi__57D1800A17C286CF 1 233057 4438738 1820.76 2646909 2/14/2011 15:57
backupset PK__backupse__21F79AAB0E391C95 1 115791 1489763 904.62 228112 6/19/2011 6:00
backupmediafamily PK__backupme__0C13C86F0880433F 1 50738 1489616 396.39 23386 7/26/2011 7:00
backupfilegroup PK__backupfi__760CD67A12FDD1B2 1 43284 2967333 338.16 1775145 2/14/2011 15:57
backupmediaset PK__backupme__DAC69E4D04AFB25B 1 29250 1489616 228.52 44462 7/22/2011 15:43
sysjobhistory clust 1 3553 33177 27.76 2428 7/25/2011 8:14

Query 2: Output

objectName indexName totalPages usedPages dataPages totalSpaceMB usedSpaceMB dataSpaceMB Rows
backupfile PK__backupfi__57D1800A17C286CF 233073 233043 231653 1820 1820 1809 4438738
backupset PK__backupse__21F79AAB0E391C95 100217 100200 99826 782 782 779 1489763
backupfilegroup PK__backupfi__760CD67A12FDD1B2 43289 43283 43077 338 338 336 1489616
backupmediafamily PK__backupme__0C13C86F0880433F 39473 39459 39287 308 308 306 2967333
backupmediaset PK__backupme__DAC69E4D04AFB25B 18737 18728 18654 146 146 145 1489616

Analyze and find out the minimum and maximum date range date available

SELECT COUNT(*) AS 'TotalRecords',
MIN(backup_start_date) AS 'MinDate',
MAX(backup_start_date) AS 'MaxDate'
FROM dbo.backupset

Resolution:
The solution is we have to purge these MSDB Backup and Restore history tables

1. The sp_delete_backuphistory system stored procedure takes a single parameter - a cutoff date. Any data older than the supplied date is purged from the msdb tables.

2. The sp_delete_database_backuphistory  system stored procedure allows you to delete historical backup data for a specific database. Unfortunately, this procedure does not offer the finer option of choosing a cutoff date. It's all or nothing.

3. sp_purge_jobhistory Removes the history records for a job.

4. Try considering creating indexes on the above said 5 tables, if no of rows are huge.
Source: http://weblogs.sqlteam.com/geoffh/archive/2008/01/21/MSDB-Performance-Tuning.aspx

use msdb
go
--backupset

Create index IX_backupset_backup_set_id on backupset(backup_set_id)
go
Create index IX_backupset_backup_set_uuid on backupset(backup_set_uuid)
go
Create index IX_backupset_media_set_id on backupset(media_set_id)
go
Create index IX_backupset_backup_finish_date on backupset(backup_finish_date)
go
Create index IX_backupset_backup_start_date on backupset(backup_start_date)
go
--backupmediaset
Create index IX_backupmediaset_media_set_id on backupmediaset(media_set_id)
go
--backupfile
Create index IX_backupfile_backup_set_id on backupfile(backup_set_id)
go
--backupmediafamily
Create index IX_backupmediafamily_media_set_id on backupmediafamily(media_set_id)
go
--restorehistory
Create index IX_restorehistory_restore_history_id on restorehistory(restore_history_id)
go
Create index IX_restorehistory_backup_set_id on restorehistory(backup_set_id)
go
--restorefile
Create index IX_restorefile_restore_history_id on restorefile(restore_history_id)
go
--restorefilegroup
Create index IX_restorefilegroup_restore_history_id on restorefilegroup(restore_history_id)
go

5. Alternatively, check when the statistics of these tables are last updated. Just run sp_updatestats.  Just try sp_delete_backuphistory  after the statistics are updated. The result is awesome! Very quick response.

Permanent Resolution

6. Further restrict the Job history growth by setting in SQL Agent –> History tab.

image

7. Also on the SQL Server Maintenance Plan “History Cleanup Task” can be of helpful

image

Thursday, May 19, 2011

SQL Server Management Studio – SSMS is a 32 bit application


SQL Server Management Studio – SSMS is a 32 bit application. Even when we install 64 bit SQL Server Database Engine, we will get 32 bit SSMS installed on the server.

Default SSMS install location

32 Bit Server C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE
64 Bit Server C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE

Monday, May 16, 2011

Maintenance Plan Error: Alter failed for Server SQLServer_Instance

 

Error message: Alter failed for Server ‘SivaSQL2008’

image 

When I ran SQL Profiler and checked why its failing, observed;
Errors when it was trying to execute

SP_CONFIGURE 'USER OPTION',0 ;
RECONFIGURE

Error: 5808, Severity: 16, State: 1
Ad hoc update to system catalogs is not supported.

The reason for why AD HOC UPDATE TO SYSTEM CATALOGS is not supported.
Why it is trying to change SYSTEM CATALOGS at first place?

In SQL Server 2000 and older, this option allowed users to make updates directly to the system tables.
In SQL Server 2005 and higher, the system tables are, replaced with the Resource Database and system views.
This option is no longer supported in SQL Server 2005 and higher version, and though we can set Allow Updates to 1 with no error. As soon as we run RECONFIGURE, we will receive the error that ad hoc updates are not supported.

Because Allow Updates had been set to 1 and my Maintenance Plan runs the RECONGIFURE statement, this error was thrown and the Maintenance Plan failed.

As per Books On Line:

Changing the allow updates option will cause the RECONFIGURE statement to fail. Changes to the allow updates option should be removed from all scripts.

Resolution:
So to resolve is configured ALLOW UPDATE back to 0 and again ran Maintenance Plan and it executes fine.

sp_configure 'allow update', 0
reconfigure

How to create scripts for an entire database or specific object in SQL Server 2008?


In this post I would like to address the requirement of;

  • How to create scripts for an entire database ?
  • How to create scripts limit it to specific objects?
  • How to restore SQL Server 2005 database on SQL Server 2000?

SQL Server Database Publishing Wizard enables the deployment of SQL Server databases into a hosted environment on either a SQL Server 2000 or 2005 server.

It generates a single SQL script file which can be used to recreate a database (both schema and data) in a shared hosting environment where the only connectivity to a server is through a web-based control panel with a script execution window.

If supported by the hosting service provider, the Database Publishing Wizard can also directly upload databases to servers located at the shared hosting provider.

We can use the Generate and Publish Scripts Wizard to create scripts for transferring a database from one instance of the Database Engine to another. You can generate scripts for a database on an instance of the Database Engine in your local network, or from SQL Azure.

The generated scripts can be run on another instance of the Database Engine or SQL Azure. 

We can also use the wizard to publish the contents of a database directly to a Web service created by using the Database Publishing Services.

We can create scripts for an entire database, or limit it to specific objects.

What version of SQL Servers are supported on this?

  Source Database Target Database 
SQL Server Instance Version Supported
  • SQL Server 2005
  • SQL Server 2008
  • SQL Server 2008 R2
  • SQL Azure
  • SQL Server 2005
  • SQL Server 2008
  • SQL Server 2008 R2
  • SQL Azure
  • SQL Server 2000
Permission needed db_ddladmin db_ddladmin
Pre-existence   The target database must be created at the hosting provider before the source database is published.
Publishing overwrites objects in that existing database

Supported Objects for Publishing

The following table lists the objects that can be published and the versions of SQL Server on which they are supported by the Generate and Publish Scripts Wizard.

Database object

SQL Server 2008 R2

SQL Server 2008

SQL Server 2005

SQL Server 2000

Application role

Yes

Yes

Yes

Yes

Assembly

Yes

Yes

Yes

No

CHECK constraint

Yes

Yes

Yes

Yes

CLR (common language runtime) stored procedure1

Yes

Yes

Yes

No

CLR user-defined function

Yes

Yes

Yes

No

Database role

Yes

Yes

Yes

Yes

DEFAULT constraint

Yes

Yes

Yes

Yes

Full-text catalog

Yes

Yes

Yes

Yes

Index

Yes

Yes

Yes

Yes

Rule

Yes

Yes

Yes

Yes

Schema

Yes

Yes

Yes

No

Stored procedure1

Yes

Yes

Yes

Yes

Synonym

Yes

Yes

Yes

Yes

Table

Yes

Yes

Yes

Yes

User2

Yes

Yes

Yes

Yes

User-defined aggregate

Yes

Yes

Yes

No

User-defined data type

Yes

Yes

Yes

Yes

User-defined function

Yes

Yes

Yes

Yes

User-defined table

Yes

Yes

No

No

User-defined type

Yes

Yes

Yes

No

View1

Yes

Yes

Yes

Yes

XML schema collection

Yes

Yes

Yes

 

1 Published without encryption.
2 Any non-system users that exist in the database are published as Roles.

How to generate SQL Scripts using Generate and Publish Scripts Wizard

We can create Transact-SQL scripts for multiple objects by using the Generate and Publish Scripts Wizard.. You can also generate a script for individual objects or multiple objects by using the Script as menu in Object Explorer.

Use the Generate and Publish Scripts Wizard to create a Transact-SQL script for many objects.
The wizard generates a script of all the objects in a database, or a subset of the objects that you select. The wizard has many options for your scripts, such as whether to include permissions, collation, constraints, and so on.

Step 1:

In Object Explorer, expand Databases, right-click a database, point to Tasks, and then click Generate Scripts. Follow the steps in the wizard to script the database objects.

image

image 

Step 2: On the Choose Objects page, select the objects to be included in the script


Script entire database and all database objects
Click to generate scripts for all objects in the database and to include a script for the database itself.

image

Step 1.3: On the Set Scripting Options page, select Save scripts to a specific location.

image

Select Save scripts to a specific location

image
Summary:

image

Click Finish.

To generate the Script for the Data on the table:

Set “Script Data: True “

 image

Select specific database objects
Click to limit the wizard to generate scripts for only the specific objects in the database that you choose.

For example I have selected Tables Object

 image

Within Tables Object, I have chosen HumanResources.Employee Table

image 

Select Save scripts to a specific location

image

Script Wizard Summary
image 

image

View of the Output file generated:

image 

References:

Using the Generate and Publish Scripts Wizard

How to: Generate a Script (SQL Server Management Studio)

Tuesday, May 10, 2011

The server principal is set as the execution context of a trigger or event notification and cannot be dropped.

 

I got error message below when i try to drop a login named ‘test_login’

Error Message:
Msg 15186, Level 16, State 1, Line 1
The server principal is set as the execution context of a trigger or event notification and cannot be dropped.

It means that there are  execute as username in a stored procedure or function or triggers, and that is why it will not allow me to drop the user.

EXECUTE permission - a check is made to see if this permission is granted. If yes the user is allowed to run the stored procedure

EXECUTE AS - when the stored procedure is run, it will run under the context of the user specified in the clause rather than the context of the user who has run it.

Use the query below find the execute as object

select object_name(object_id)
from sys.sql_modules
where execute_as_principal_id = user_id('test_login')

How to find the Dynamic Management Views on SQL Server Management Studio?

 

Expand the Views –> System Views on each database nodes.

image

Saturday, December 18, 2010

Download Microsoft SQL Server 2005 Service Pack 4 RTM

 

Service Pack 4 (SP4) for Microsoft SQL Server 2005 is now available for download.

SQL Server 2005 SP4 includes SQL Server 2005 SP3 cumulative update 1 to 11, customer requested fixes, along with instances of the SQL Server 2005 SP4 database Engine support for DAC operations.

It can be downloaded from

Microsoft SQL Server 2005 Service Pack 4 RTM

Thursday, December 16, 2010

SQL Server has encountered 2 occurrence(s) of cachestore flush for the 'Bound Trees' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.

 

Error:
SQL Server has encountered 2 occurrence(s) of cachestore flush for the 'Bound Trees' cachestore (part of plan cache) due to some database maintenance or reconfigure operations.

Cause:
When we take the database OFFLINE this error raised.

Reference: http://support.microsoft.com/kb/917828

Wednesday, December 15, 2010

The server principal is not able to access the database under the current security context.

 

I reproduced the error below;

Issue 1:

Msg 916, Level 14, State 1, Line 1
The server principal "Test_Login" is not able to access the database "testdb" under the current security context.

1. Created database ‘testdb’

2. Created the login ‘Test_Login’. The login not granted access on the database ‘testdb’

3. On logging on ‘Test_Login’, tried accesing the database ‘testdb’ and got the error.

clip_image002

From the error message, when the server principal ( login) does not have access on the database the error occurs.

Resolution 1:
Grant the database access for the login. For example;

Use testdb
go

Create User Test_Login for Login Test_Login
go

Issue 2:

The database is in “Restricted Mode”

image

Try the query below, to access the database in different user context

Use testdb
go
execute as user='test_login'
go

Msg 916, Level 14, State 1, Line 1
The server principal "Test_Login" is not able to access the database "testdb" under the current security context.


Reference : 
"The server principal LoginName is not able to access the database DatabaseName under the current security context"

Thursday, November 18, 2010

TSQL Query to find the DB Maintenance status

 

Are you curious to find the Database Backup / Restore status?
Do you have to find out the status the DBCC CHECKDB ?
Do you have to report when the ROLLBACK would finish ?
Do you want judge how long the Database Shrink will take?

Here is the answer!

The query listed below can be used to find the Percentage of work completed for the following commands:

  1. ALTER INDEX REORGANIZE
  2. AUTO_SHRINK option with ALTER DATABASE
  3. BACKUP DATABASE
  4. DBCC CHECKDB
  5. DBCC CHECKFILEGROUP
  6. DBCC CHECKTABLE
  7. DBCC INDEXDEFRAG
  8. DBCC SHRINKDATABASE
  9. DBCC SHRINKFILE
  10. RECOVERY
  11. RESTORE DATABASE,
  12. ROLLBACK
  13. TDE ENCRYPTION

We have to replace the where condition filter based on the requirement.

SELECT command,
            sqltext.text,
            start_time,
            percent_complete,
            CAST(((DATEDIFF(s,start_time,GetDate()))/3600) as varchar) + ' hour(s), '
                  + CAST((DATEDIFF(s,start_time,GetDate())%3600)/60 as varchar) + 'min, '
                  + CAST((DATEDIFF(s,start_time,GetDate())%60) as varchar) + ' sec' as running_time,
            CAST((estimated_completion_time/3600000) as varchar) + ' hour(s), '
                  + CAST((estimated_completion_time %3600000)/60000 as varchar) + 'min, '
                  + CAST((estimated_completion_time %60000)/1000 as varchar) + ' sec' as est_time_to_go,
            dateadd(second,estimated_completion_time/1000, getdate()) as est_completion_time
FROM sys.dm_exec_requests Req
CROSS APPLY sys.dm_exec_sql_text(Req.sql_handle) sqltext
WHERE req.command in ('DBCC CHECKDB')

Wednesday, October 20, 2010

On SQL Server Management Studio, How to list only the database, which user has access ?

 

The default behavior of SSMS when we login, it will show all the databases available on the SQL Server Instance. Irrespective of access on the databases user has.

The reason behind is, to load the SSMS faster. Otherwise, while loading the SSMS SQL Server has to verify for each databases if the user has access or not. Also if any of the databases or offline or closed, it has to figure out if that database has to be listed or not. All this takes time.
Hence by default the SSMS will show all the databases on SSMS.

If we really required to show only the database user has access, please use the command below to restrict the show all databases on SSMS,

DENY VIEW ANY DATABASE TO login_name

When VIEW ANY DATABASE is revoked, a user can only see master, tempdb, any database he owns, and the user’s current database context.

Tuesday, August 10, 2010

MOSS – Microsoft Office Sharepoint Server 2007 SQL Server 2005 / 2008 Database Maintenance

 

There is a whitepaper in detail SQL Server 2005 /2008 Maintenance for MOSS ( Sharepoint ).

Database Maintenance for SharePoint