Skip to main content

Posts

Showing posts from July, 2014

Clustered index and non clustered index in SQL

Clustered index which reordered the table and saved separately as index table(data pages stored as B-tree) there can be one clustered index per db & Non clustered index is typically a index(data pages stored as heap) A table can have only one clustered index with many non clustered indexes. The leaf nodes of the cluster index stores data pages and non clustered index stores key values(where as table includes clustered index) or rid's(table contains non cluster index only).

Advantage and disadvantage of Team Viewer , Ammy Admin and show my PC etc

Advantage of Team Viewer , Ammy Admin and show my PC etc You can share your desktop to other user or pc to take live support help from your friend or colleague. You can also help to other friends also. If you want to use limited hours in a month use of   Team Viewer , Ammy Admin and show my PC then you can use trial version but if you want to use lot of time in a single month then you need to buy license. You can buy license online. Disadvantage of Team Viewer , Ammy Admin and show my PC Mostly these type of connections registers all clicks and keypress, that means they can know about all your logins and passwords and you PC could be hacked or misused(Its possibility but mostly they do not do it).

How will you upgrade for Active and Active cluster server

To upgrade for Active & Active cluster server Active to active means you will install SQL server on each node so they will be active to active. First transfer both sql server service on node A and upgrade Node B then transfer both services on node B and upgrade node A and then split the service on separate nodes(Node A & B)

Datebase-Unavailable database:testdb is unavailable(suspect,offline,recovering etc) in SQL

SQL Error:  Database-Unavailable database  :testdb is unavailable(suspect,offline,recovering etc) 1.If the database is offline, the approach should be to bring the database online by either from GUI or from query : ALTER DATABASE <database_name> SET ONLINE and if it still doesn't come up..we should check the logs for the reasons..and based on the outcome we have to proceed accordingly. 2.If the Database is offline, then try to make the database online using the script ALTER DATABASE <database name> SET ONLINE. If it is not recover the database to online, then check in event viewer for possible error, if error is 17204--then data file has damaged,if error is 17207--- then log file has damaged,If you see this error then the database is there in suspect state. To Recover the suspect state database u need to follow steps as below: If data file damaged: 1. Take the tile log back up. 2.Restore Full back up with no recovery. 3.Restore Differential & Log Backups

How to Shrink TempDB in Sql Server?

To Shrink TempDB in Sql Server below ideas can help you to handle the issue. If it is data file then Instead of shrinking you should check the open transactions causing tempdb to get full..if it is not critical you can kill the process or else should add secondary data files. Shrinking log whereas is safe witch you can do by dbcc shrinkfile command. 1)If mdf file is full we can shrink that but sometimes we can’t shrink mdf file the reasons are: (i)check if any locks are there through (sys.dm_tran_locks)or sp_locks (ii)check for sys.dm_db_session_space_usage which will allows to check for page allocation and deallocation for each session on that instance (iii)check for temporary objects in tempdb using (select * from sys.all_objects where is_ms_shipped=0)-ser created temp objects. These are called as cached objects which are residing in procedure cache which helps stored procedure to make use of the query plan. But now it is not getting shrinked we have to perform DBCC FREEPROCCACHE wh

Database Administrator daily tasks

These are the task list that must be done by a DBA on daily basis. 1) Check System Event Logs and SQL Server Error Logs for unusual events. 2) Verify that all scheduled jobs have run successfully. 3) Confirm that backups have been made and successfully and moved to the backup storage or secure location. 4) Monitor disk space to make sure SQL Servers will not run out of disk space. 5) Periodically monitor performance of database and system using both System Monitor and SQL Server Profiler. 6) Monitor and identify blocking issues. 7) Keep a log of any changes you make to servers, instance setting, database setting and monitoring script. 8) Create SQL Server alerts to notify you of problems, and e-mailed to you. Take action as  needed. 9) Regularly restore backups to a test server in order to verify that you can restore them. Summary: Installing DB software Creating databases Performing upgrades of the database and software to new release levels Starting u

Index rebuilding in SQL

When index are rebuild that means the old indexes on the table are dropped and new indexes on the table are created. Due to the creation of the indexes on the table all the data is organised in the leaf level (cluster index) and organised simultaneously. Thus maximum the number of rows in your table , maximum will be the page count and maximum will be the time taken in rebuilding the index. Indexing is nothing but ordering of pages, thus it depends on page count

SQL DBA Checklist

Following can be SQL DBA Checklist on daily,weekly and monthly basis. 1.SQL DBA daily checklist can include Database backup status, Database integrity checks, failed jobs. 2.Weekly checklist can include index reorganization, update stats etc . 3.Monthly checklist can include Restoration drill for critical databases to ensure backup's availability in case of any unusual happening etc.these are general points.although it depends on current environment and issues how you define your checklist as a DBA.

Some Light on Roleback and commit transaction in sql recovery mode

If log truncation is performed when your transaction is still running then it will truncate only committed transactions and there is no impact on the current running transaction. if your transaction is completed and after that log truncation is performed it will clear your transaction. SQLServer internally maintain some lsn or modified pages details in one page so if you rebooted the server, if transaction is completed then changes applied into mdf files and there is no change in the DB and it will online after reboot. But if you rebooted the server in the middle of transaction then after server is online , database went into recovery mode and it will rollback all changes as per the changes after all the rollback completes DB will come into online .

Way to find differential backup for SQL Database

1.Check MSDB backup history for that database select * from msdb.dbo.backupset where name='dbname' and type='i' order by backup_finish_date desc 2.dbo.backupset: provides information concerning the most-granular details of the backup process dbo.backupmediafamily: provides metadata for the physical backup files as they relate to backup sets dbo.backupfile: this system view provides the most-granular information for the physical backup files USE AdventureWorks GO SELECT TOP 100 s.database_name, m.physical_device_name, CAST(CAST(s.backup_size / 1000000 AS INT) AS VARCHAR(14)) + ' ' + 'MB' AS bkSize, CAST(DATEDIFF(second, s.backup_start_date, s.backup_finish_date) AS VARCHAR(4)) + ' ' + 'Seconds' TimeTaken, s.backup_start_date, CAST(s.first_lsn AS VARCHAR(50)) AS first_lsn, CAST(s.last_lsn AS VARCHAR(50)) AS last_lsn, CASE s.[type] WHEN 'D' THEN 'Full' WHEN 'I' THEN 'Differential' WHEN &

How To Identify The Long Running Queries in SQL?

These queries can help you  To Identify The Long Running Queries in SQL. 1.SELECT creation_time ,last_execution_time ,total_physical_reads ,total_logical_reads ,total_logical_writes , execution_count , total_worker_time , total_elapsed_time , total_elapsed_time / execution_count avg_elapsed_time ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1, ((CASE statement_end_offset WHEN -1 THEN DATALENGTH(st.text) ELSE qs.statement_end_offset END - qs.statement_start_offset)/2) + 1) AS statement_text FROM sys.dm_exec_query_stats AS qs CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st where total_elapsed_time >= 800000000 ORDER BY total_elapsed_time / execution_count DESC; 2.DBCC opentran(This command will display the longest running transactions on the database) and select * from sys.dm_tran_active_snapshot_database_transactions(this command will display the transactions about replication and mirroring and snapshot isolated related transactions)

How to add multiple foreign keys in a table from different reference tables in SQL

To  add multiple foreign keys in a table from different reference tables in SQL you can try below methods in sql query editor. 1. Alter table table_name add constraint constraint_name foreign key(col_name) references table_name(col_name) GO. 2.Create foreign constraint WITH NOCHECK first then CHECK it with another alter statement.. Make sure to put GO in between each statement.. Just to safe side, SET ANSI PADDING ON on the top and OFF at the button..

How to add multiple log files in SQL Database

Below query can create ldf file.Its creating second ldf file on Testdb Database. You can create as many as you want. USE [master] GO ALTER DATABASE [TestDb] ADD LOG FILE ( NAME = N'TestDB_Log2', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQL2008R2\MSSQL\DATA\Testdb_Log2.ldf' , SIZE = 1024KB , FILEGROWTH = 10%) GO I Hope this could be your expected solution.

How to patch service pack for sql server clustering?

Patch the passive node first then reboot the node and then fail over instance on that node and then in similar manner patch the other node. This you can apply for sql 2008 and above. In SQL Server 2012, there is a Cluster Aware Update that will automatically Update all the nodes. Start applying the service pack on the passive node and then failover the instance to passive node after the installation is over on the passive node now start applying the service pack on active node and again fail-over the node. On SQL Server 2008/ 2008R2 : Apply patches/hot-fixes on passive node(N2) first then reboot the server. once the passive node(N2) is up, fail-over the resources from active node(N1) to passive node(N2), perform the same steps on N1 node and fail-over the resources from N2 to N1. On SQL Server 2005 : Apply patches/hot-fixes only on active node(N1), same will be applied on passive node(N2) too. On SQL Server 2005 we need down time during this activity. But on SQL server 2008/2008R2 we

How to add files to logshipped SQL database?

Run log back up job on primary server and disable backup job to make sure not to run any backup jobs further until we enable again. check the log back ups if there are any need to be restored on secondary db, restore them if any until all the log backups complete. Then disable the log shipping add mdf-ldf file take a log backup and restore the same on secondary database them enable log shipping and enable backup job as well. If the drives and path exist on secondary log shipping will not break, if the drives are different obviously log shipping will fail.u have to disable all jobs in primary make sure that in between no backups will happen. restore that log file backup with move option. If the path of both files are same it wont break logshipping. If.If path is different then manually restore that particular log backup with move option.

What is latches in sql server

Microsoft SQL Server provides counters to monitor internal SQL Server resource called latches.Monitoring the latches to determine user activity and resource usage can help you to identify performance bottlenecks like Average Latch Wait Time,Waits/sec We can monitor the performance by using cpu usage and memory usage what is use of latch. Latches are light weight locks which SQL server acquires for pages in buffer. Latch is a synchronization mechanism between threads.Latch protects access to in memory data structures. latches are lightweight as compare to locks. the best example to understand latch is TEMP DB LATCH CONTENTION.