Feeds:
Posts
Comments

Archive for the ‘SQL Server’ Category

Normally to find out whether or not a trigger is enabled/disabled, we can simply run this:
SELECT OBJECTPROPERTYEX (OBJECT_ID(‘TriggerName’),’ExecIsTriggerDisabled’)
A DDL trigger, however, is not schema-scoped, therefore the above query will return NULL. To find out, here’s the query that you need to run:
SELECT name, is_disabled
FROM sys.triggers
WHERE name = ‘TriggerName’

Read Full Post »

How to Create An Empty Database

Not a new database, but an empty database – no data, but it still preserves the existing schema. You have choices:
1. Use a combination of Truncate/Delete
USE MyDB
EXEC sp_msforeachtable ‘print ‘’TRUNCATE TABLE ?’’’
The command will truncate all tables in the database, EXCEPT when a column in a table has a constraint such as a foreign key. [...]

Read Full Post »

Cursors have been taught as a no-no in SQL programming, mostly because it is resource-intensive. Of course, there will be some exceptional cases where the use of cursors is justified. In my case, I used cursors because it feels familiar. If you have learnt some procedural ‘ancient’ programming languages, you would understand what I [...]

Read Full Post »

In SQL Server 2000:
select * from ::fn_virtualservernodes()
In SQL Server 2005:
select * from sys.dm_os_cluster_nodes
Or this backward compatibility function:
select * from fn_virtualservernodes()
Reference: BOL

Read Full Post »

To automatically map users to the SQL logins on the server:
exec sp_change_users_login ‘Auto_fix’
To find orphaned users ( users with no logins):
Use
exec sp_change_users_login @Action = ‘Report’
Reference: BOL

Read Full Post »

In SQL Server 2000, you can easily rename your database running sp_renamedb. The syntax from BOL as follows:
sp_renamedb [ @dbname = ] ‘old_name’ , [ @newname = ] ‘new_name’
In SQL Server 2005, however, this has changed. You will need to use ALTER DATABASE MODIFY NAME instead.
ALTER DATABASE database_name
MODIFY NAME = new_database_name
Although the database [...]

Read Full Post »

I read the other day about indexing small tables I’d like to test this on my database but first I would need to find out which tables do not have an index and/or a primary key.
Pinal Dave wrote about finding tables without a clustered index or a primary key:
SELECT DISTINCT [TABLE] = OBJECT_NAME(OBJECT_ID)
FROM SYS.INDEXES
WHERE [...]

Read Full Post »

Querying sp_who2

Wouldn’t you wish sometimes you can just query the sp_who2 results? The only way to do this is to create a temporary table to dump the result, and then query the table. You can use SELECT statement as per normal.
CREATE TABLE #who
(SPID INT,
Status VARCHAR(1000) NULL,
Login SYSNAME NULL,
HostName SYSNAME NULL,
BlkBy SYSNAME NULL,
DBName SYSNAME NULL,
Command VARCHAR(1000) [...]

Read Full Post »

Following my previous post on how to uninstall SQL Server 2008 instance, this time I am writing about how to uninstall the SQL Express 2005. Here’s the thing: I have already had a SQL Server 2005 Developer instance when I installed the SQL Express 2005. I can’t tell apart the double-installed SQL Server 2005, so [...]

Read Full Post »

There are times when you want to know who the users are in a particular group. Depending on your level of privileges, there are various ways to get this information:
1. You can find out about it using the SQL Server Management Studio or Query Analyzer:

EXEC xp_logininfo ‘DOMAIN\group_name’,’members’
To run this, you will need to have [...]

Read Full Post »

Older Posts »