List of DMV in SQL Server 2005 and 2008
Posted by Ravi Khanal on Jan 31, 2009
Dynamic Management Views(DMVs) are system views that surface the internal counters of the database engine and help present an easily comprehendible dashboard of the database engine performance that can be used to monitor the health of a server instance, diagnose problems, and tune performance.
List of DMV in SQL Server 2005
1. sys.dm_broker_activated_tasks
2. sys.dm_broker_connections
3. sys.dm_broker_forwarded_messages
4. sys.dm_broker_queue_monitors
5. sys.dm_clr_appdomains
6. sys.dm_clr_loaded_assemblies
7. sys.dm_clr_properties
8. sys.dm_clr_tasks
9. sys.dm_db_file_space_usage
10. sys.dm_db_index_usage_stats
11. sys.dm_db_mirroring_connections
12. sys.dm_db_missing_index_details
13. sys.dm_db_missing_index_group_stats
14. sys.dm_db_missing_index_groups
15. sys.dm_db_partition_stats
16. sys.dm_db_session_space_usage
17. sys.dm_db_task_space_usage
18. sys.dm_exec_background_job_queue
19. sys.dm_exec_background_job_queue_stats
20. sys.dm_exec_cached_plans
21. sys.dm_exec_connections
22. sys.dm_exec_query_memory_grants
23. sys.dm_exec_query_optimizer_info
24. sys.dm_exec_query_resource_semaphores
25. sys.dm_exec_query_stats
26. sys.dm_exec_query_transformation_stats
27. sys.dm_exec_requests
28. sys.dm_exec_sessions
29. sys.dm_fts_active_catalogs
30. sys.dm_fts_index_population
31. sys.dm_fts_memory_buffers
32. sys.dm_fts_memory_pools
33. sys.dm_fts_population_ranges
34. sys.dm_io_backup_tapes
35. sys.dm_io_cluster_shared_drives
36. sys.dm_io_pending_io_requests
37. sys.dm_os_buffer_descriptors
38. sys.dm_os_child_instances
39. sys.dm_os_cluster_nodes
40. sys.dm_os_hosts
41. sys.dm_os_latch_stats
42. sys.dm_os_loaded_modules
43. sys.dm_os_memory_allocations
44. sys.dm_os_memory_cache_clock_hands
45. sys.dm_os_memory_cache_counters
46. sys.dm_os_memory_cache_entries
47. sys.dm_os_memory_cache_hash_tables
48. sys.dm_os_memory_clerks
49. sys.dm_os_memory_objects
50. sys.dm_os_memory_pools
51. sys.dm_os_performance_counters
52. sys.dm_os_ring_buffers
53. sys.dm_os_schedulers
54. sys.dm_os_stacks
55. sys.dm_os_sublatches
56. sys.dm_os_sys_info
57. sys.dm_os_tasks
58. sys.dm_os_threads
59. sys.dm_os_virtual_address_dump
60. sys.dm_os_wait_stats
61. sys.dm_os_waiting_tasks
62. sys.dm_os_worker_local_storage
63. sys.dm_os_workers
64. sys.dm_qn_subscriptions
65. sys.dm_repl_articles
66. sys.dm_repl_schemas
67. sys.dm_repl_tranhash
68. sys.dm_repl_traninfo
69. sys.dm_tran_active_snapshot_database_transactions
70. sys.dm_tran_active_transactions
71. sys.dm_tran_current_snapshot
72. sys.dm_tran_current_transaction
73. sys.dm_tran_database_transactions
74. sys.dm_tran_tran_locks
75. sys.dm_tran_session_transactions
76. sys.dm_tran_top_version_generators
77. sys.dm_tran_transactions_snapshot
78. sys.dm_tran_version_store
New DMV in SQL Server 2008
1. sys.dm_audit_actions
2. sys.dm_audit_class_type_map
3. sys.dm_cdc_errors
4. sys.dm_cdc_log_scan_sessions
5. sys.dm_cryptographic_provider_properties
6. sys.dm_database_encryption_keys
7. sys.dm_db_mirroring_auto_page_repair
8. sys.dm_db_mirroring_past_actions
9. sys.dm_db_persisted_sku_features
10. sys.dm_db_script_level
11. sys.dm_exec_procedure_stats
12. sys.dm_exec_trigger_stats
13. sys.dm_filestream_file_io_handles
14. sys.dm_filestream_file_io_requests
15. sys.dm_fts_fdhosts
16. sys.dm_fts_outstanding_batches
17. sys.dm_os_dispatcher_pools
18. sys.dm_os_dispatchers
19. sys.dm_os_memory_brokers
20. sys.dm_os_memory_node_access_stats
21. sys.dm_os_memory_nodes
22. sys.dm_os_nodes
23. sys.dm_os_process_memory
24. sys.dm_os_spinlock_stacks
25. sys.dm_os_sys_memory
26. sys.dm_resource_governor_configuration
27. sys.dm_resource_governor_resource_pools
28. sys.dm_resource_governor_workload_groups
29. sys.dm_server_audit_status
30. sys.dm_tran_commit_table
31. sys.dm_xe_map_values
32. sys.dm_xe_object_columns
33. sys.dm_xe_objects
34. sys.dm_xe_packages
35. sys.dm_xe_session_event_actions
36. sys.dm_xe_session_events
37. sys.dm_xe_session_object_columns
38. sys.dm_xe_session_targets
39. sys.dm_xe_sessions
How to Synchronize Logins and manage Orphaned Users
Posted by Ravi Khanal on Dec 19, 2008
Database movement between servers is one of the common task for the DBA. But when the database is moved from one server to another or from one instance to other, the logins do not get transferred. So as a DBA you have to manually transfer the logins to remove this problem.
So let’s discuss what is the cause behind this. SQL Server logins are stored in the master database and they are mapped against individual databases. The Login informations on SQL Server 2005 are visible through sys.server_principals system catalog view and the sys.logins view. The mapping information of the database user is stored in the sysusers system table. This table includes the name of the database user and the SID of the corresponding SQL Server Login. The SID is the security identifier and SID tracks the logins throughout the entire systems.
So when we move or copy our database from one server to another or from one instance to another then the windows login will have the same SID but the SQL logins may have the different SIDs. So when the SID of the new server instance and the older instance doesn’t matches we have a Orphaned User.
Sample SSIS Package
Posted by Ravi Khanal on Dec 6, 2008
Scenario:
In the inbound location, I have to create a directory which would be like “DealerSales and Current Date” and then download files from the remote location to that directory. Then I have to move the files from there to the working directory. Then I have to unzip the zip files and load the text files to the database and delete the text files from the working directory and move the zip from the working directory to the Archive folder. The directory’s date format should be in MMDDYYYY format.
Solution:
There could be a different approach to make the SSIS Package. One of the easier way to make the Package for this type of scenario could be like this:
- Let’s first have the File System Task which will create a directory like “DealerSales12052008″ inside download directory, if it doesn’t exist.
- Then let’s have the FTP Task which will download files from remote location to that folder.
- Then let’s have the File System Task which will create a directory like “DealerSales12052008″ inside the working directory, if it doesn’t exist.
- Then let’s have the For Each Loop Container and File System task which will move files from download directory to the working directory.
- Then let’s have the For Each Loop Container and Execute Process Task which will unzip the Zip files.
- Then let’s have the For Each Loop Container and Data Flow Task which will load all the text files into the SQL Server database.
- Then let’s have the File System Task which will create a directory like “DealerSales12052008″ inside the Archive Directory.
- Then let’s have the For Each Loop Container and File System Task which will move the zip files to the Archive Directory.
- Then let’s have the For Each Loop Container and File System Task which will delete the text files from the working directory.
- Then let’s have a File System tasks which will clean up our download directory and working directory.
So now let’s begin by making the skeleton of the package by dragging the task and which would look like this:
T-SQL vs PL-SQL
Posted by Ravi Khanal on Oct 15, 2008
Microsoft’s T-SQL is similar to Oracle’s PL-SQL to some extent, but they are very different in some important and basic ways. Some of the basic differences are:
- The difference in the datatype:
- In T-SQL Datetime is represented as 1/300th Second and in PL-SQL date is represented as 1 second and Timestamp as 1/100 millionth Second.
- The default date format of PL-SQL doesnot include time part.
- In T-SQL, there is no need of dual. The T-SQL Syntax will look like:
select getdate()
The PL-SQL will look like
slect sysdate from dual - INSTEAD OF trigger is used in SQL Server as an equivalent to Oracle’s BEFORE trigger.
- CASE expressions can be used in SQL Server for Oracle’s DECODE() function.
- In T-SQL there is an IDENTITY function which is more simpler than the SEQUENCE of PL-SQL. For implementing Sequence in PL-SQL, you have to create a new object called SEQUENCE and also we should have the trigger.
- You cant have multiple databases on an Oracle Instance but you can have multiple databases on a SQL Server Instance.
- In T-SQL there is SELECT INTO. In PL-SQL you have to use INSERT INTO.
T-SQL:select getdate() newcolumn into newtable;
PL-SQL:insert into newtable(newcolumn) values (sysdate); - In PL-SQL there is MINUS operator. In T-SQL you have to use NOT EXISTS clause in Select statement to generate the same result.
- T-SQL’s RAISEERROR does not break the flow. It simply returns an error string or message but the stored procedure still returns normally. PL-SQL’s raise_application_error throws an exception, exits the current stored procedure, rolls back till implicit savepoint at the beginning of the stored procedure.
- In T-SQL, stored procedure do not rollback automatically if something fails. You can use TRY CATCH but still the roll back is optional. In PL-SQL, stored procedures are atomic. Any error inside a stored procedure rolls back up to the point where the stored procedure was called.
| T-SQL | PL-SQL |
| Integer, SmallInt, TinyInt, Bit | NUMBER |
| Varchar | Varchar2 |
| Text | CLOB |
| IMAGE | BLOB |
| BINARY(n), VARBINARY | RAW(n) or BLOB |
| MONEY | NUMBER(19,4) |
| DATETIME, SMALL-DATETIME | DATE |
| NVARCHAR(n) | VARCHAR(n*2) |
| TIMESTAMP | NUMBER |
Database Migration best practices
Posted by Ravi Khanal on Jun 4, 2008
Database Migration is always a very challenging job since data is the major component of any System and it should always be secured. You are not migrating database when any new version of the database is in the market. You have to spend a lot time researching whether the database migration is really fruitful. After the data migration from one version to another, you should have the all the usefullness of the previos version with the usefullness of the new one.
Some of the best practice that I used to follow while migrating database from SQL Server 2000 to SQL Server 2005 are:
Read the rest of this entry »
