Using Catalog Views – sys.check_constraints
sys.check_constraints contains a row for each CHECK constraint. It contains below useful columns: 1. parent_column_id – column id for which CHECK constraint is defined 2. parent_object_id – id of the...
View ArticleUsing Catalog Views – sys.foreign_keys
sys.foreign_keys contains a list of all FOREIGN KEYS in the database. It contains one row per FOREIGN KEY. Below is a list of some columns returned by this view: 1. Name – FOREIGN KEY name, 2....
View ArticleUsing Catalog Views – sys.views
sys.views returns a row for each view in the database, sys.views only returns rows for which the user owns or has been granted permission for. Below are some of the columns returned by sys.views. 1....
View ArticleSQL Server – Login Auditing
SQL Server Login Auditing can be used to monitor login activities on SQL Server Database Engine. SQL Server can log both failed and successful login attempts on the server. It provides four different...
View ArticleSQL Server – Login Auditing using Logon Triggers
Since SQL Server 2005 we have LOGON Triggers, these are DDL Triggers which are created at Server level. These triggers are created to respond to a Login Event. LOGON Trigger executes after the...
View ArticleSQL Server – Management Studio – Schema Changes History Report
Schema Changes History Report produces the list of changes done using DDL. It pulls this information from the Default Trace. You can access the report from Management Studio: 1. Right Click on...
View ArticleSQL Server – Auditing Schema Changes using DDL Triggers
Yesterday, I posted about SQL Server – Management Studio – Schema Changes History Report and Default Trace and their limitations. It does not capture the details of modification. i.e. When a new column...
View ArticleSQL Server – Server-related dynamic management views in SQL Server 2008 SP1...
There are three new server-related DMVs introduced in SQL Server 2008 R2 Service Pack 1 and SQL Server Codename "Denali". 1. sys.dm_server_services: - For SQL Server 2008 R2 SP1, it contains...
View ArticleSQL Server – How to identify service pack installed
Identifying current service pack installed for SQL Server can be difficult if you don’t know which command to use! Most of the time I have seen people using @@VERSION to check for SQL Server service...
View ArticleSQL Server – Identifying default data directory for multiple instances...
This is a follow up post from a comment on my blog. Earlier I posted about using xp_instance_regread to get default data location for current instance. It translates a given registry path to instance...
View ArticleSQL Server – Login Failed, cannot open user default database
Each login in SQL Server has a default database associated with it. When you login to SQL Server context is set to default database for login. This is set when login is created and it can be changed by...
View ArticleSQL Server – Enabling backup CHECKSUM with Trace Flag 3023
You can use WITH CHECKSUM option to perform checksum when backup is created. When used this verifies each page for checksum and torn page. You can use it in a BACKUP command as below: BACKUP DATABASE...
View ArticleSQL Server – Check Enabled Trace Flags for Server
In SQL Server you can enable a Trace Flag at session (effective for current session only) level and global level. If you are not sure which Trace Flags have been enabled you can use DBCC TRACESTATUS()...
View ArticleSQL Server – Cycle Error Logs for SQL Server and SQL Server Agent
SQL Server error logs can fill up quickly, and when you are troubleshooting something you may need to go through huge log. However you can cycle the error log to manage the amount of log you need to go...
View ArticleSQL Server – Start/Stop SQL Server from command line
You can start/stop SQL Server services using Services Console or SQL Server Configuration Manager. You can also perform these operation using command line in Windows. For this you must run command...
View ArticleSQL Server – Changing Default Database Location for Server
When you create a new database in SQL Server without explicitly specifying database file locations, SQL Server created files in default location. This default location is configured when installing SQL...
View ArticleSQL Server – How to check if you are running 32-bit or 64-bit version
There are two different command you can use to check if you are running 32-bit or 64-bit version of SQL Server. Using @@VERSION: You can user @@VERSION system variable to determine edition and...
View ArticleSQL Server – Finding TCP Port Number SQL Instance is Listening on
By default SQL Server listens on TCP port number 1433, and for named instances TCP port is dynamically configured. There are several options available to get the listening port for SQL Server Instance....
View ArticleSQL Server – How to find Default data and log path for SQL Server 2012
To identify default data and log directories in SQL Server 2012 you can use SERVERPROPERTY() function. In SQL Server 2012 two new parameters are added to SERVERPROPERTY() function namely,...
View ArticleSQL Server – Show/Hide Results Pane in Management Studio 2012
In earlier version of SQL Server Management Studio (2005, 2008 and 2008 R2) you can show/hide results pane using keyboard shortcut Ctrl+R. This shortcut was also present in Query Analyzer (SQL Server...
View Article