1. Can we hot add CPU to the SQL server?
Ans: Yes! Adding CPUs can occur physically by adding new hardware, logically by online hardware partitioning, or virtually through a virtualization layer. Starting with SQL Server 2008, SQL Server supports hot-add CPU.
- Requires hardware that supports hot-add CPU.
- Requires the 64-bit edition of Windows Server 2008 Datacenter or the Windows
- Server 2008 Enterprise Edition for Titanium-Based Systems operating system.
- Requires SQL Server Enterprise.
- SQL Server cannot be configured to use soft NUMA
- Once the CPU is added just run RECONFIGURE then the SQL server recognizes the newly added CPU.
2. How can we check whether the port number is connecting or not on a Server?
- TELNET <HOSTNAME> PORTNUMBER
- TELNET PAXT3DEVSQL24 1433
- TELNET PAXT3DEVSQL24 1434
- MSSQL Server: 1433
- HTTP TCP 80
- HTTPS TCP 443
3. What is the port numbers used for SQL Server services?
- The default SQL Server port is 1433 but only if it’s a default install. Named instances get a random port number.
- The browser service runs on port UDP 1434.
- Reporting services is a web service – so it’s port 80, or 443 if it’s SSL enabled.
- The analysis service is on 2382 but only if it’s a default install. Named instances
- get a random port number.
4. Start SQL Server in different modes?
Ans: Single User Mode (-m) : sqlcmd –m –d master –S PAXT3DEVSQL11 –c –U sa –P *******
DAC (-A): sqlcmd –A –d master –S PAXT3DEVSQL11 –c –U sa –P *******
Emergency: ALTER DATABASE test_db SET EMERGENCY
5. How to recover a database that is in suspect stage?
Ans: ALTER DATABASE test_db SET EMERGENCY
After you execute this statement SQL Server will shutdown the database and restart it without recovering it. This will allow you to view / query database objects, but the database will be in read-only mode. Any attempt to modify data will result in an error similar to the following:
Msg 3908, Level 16, State 1, Line 1 Could not run BEGIN TRANSACTION in database ‘test’ …..etc
ALTER DATABASE test SET SINGLE_USER
DBCC CHECKDB (‘test’, REPAIR_ALLOW_DATA_LOSS) GO
If DBCC CHECKDB statement above succeeds the database is brought back online (but you’ll have to place it in multi-user mode before your users can connect to it). Before you turn the database over to your users you should run other statements to ensure its transactional consistency. If DBCC CHECKDB fails then there is no way to repair the database – you must restore it from a backup.
6. Can we uninstall/rollback service packs from SQL Server 2005?
Ans: No not possible for SQL Server 2005. To rollback a SP you have to uninstall entire product and reinstall it.
For SQL Server training Bangalore 2008 you can uninstall a SP from Add/Remove programs.
Some people are saying that we can do it by backup and replace the resource DB. But I am not sure about that.
7. What is a deadlock and what is a live lock? How will you go about resolving deadlocks?
Ans: Deadlock is a situation when two processes, each having a lock on one piece of data, attempt to acquire a lock on the other’s piece. Each process would wait indefinitely for the other to release the lock unless one of the user processes is terminated. SQL Server detects deadlocks and terminates one user’s process.
A livelock is one, where a request for an exclusive lock is repeatedly denied because a series of overlapping shared locks keeps interfering. SQL Server detects the situation after four denials and refuses further shared locks. A livelock also occurs when read transactions monopolize a table or page, forcing a write transaction to wait indefinitely.
8. SQL Server is not responding. What is action plan?
Ans: Connect using DAC via CMD or SSMS
- Connect via CMD
- SQLCMD -A –U my admin login –P password -SMyServer –master
- Once you connect to the master database run the diagnostic quires to find the problem
- Correct the issue and restart the server
Find the errors from SQL log using
SQLCMD –A –SmyServer –q”Exec xp_readerrorlog” –o”C:logout.txt”
A long-running query blocking all processes and not allowing new connections
Write a query and put the script file on hard disk Ex: D:ScriptsBlockingQuery.sql
select p.spid, t.text
from sys processes p
CROSS APPLY sys.dm_exec_sql_text (sql_handle) t
where p.blocked = 0
and p.spid in
( select p1.blocked
from sys processes p1
where p1.blocked > 0
and p1.waittime > 50 )
From the command prompt run the script on the SQL server and get the result to a text file
SQLCMD -A – SMyServer -i”C:SQLScriptsGetBlockers.sql” -o”C:SQLScriptsblockers.txt”
Recently added some data files to temp DB and after that SQL Server is not responding
This can occur when you specify new files in a directory to which the SQL Server service account does not have access.
Start the SQL Server in minimal configuration mode using the startup parameter “–f”. When we specify –f the SQL server creates new tempdb files at default file locations and ignores the current tempdb data files configuration. Take care when using –f as it keep the server in single-user mode.
Once the server is started change the tempdb configuration settings and restart the server in full mode by removing the flag -f
A database stays in a SUSPECT or RECOVERY_PENDING State
Try to resolve this using CheckDB and any other DBCC commands if you can.
Last and final option is put the DB in emergency mode and run CHECKDB with repair_allow_data_loss
(Note: Try to avoid this unless you don’t have an option as you may lose large amounts of data)
9. Why SQL server is better than other databases?
Ans: I am not going to say one is better than others, but it depends on the requirements. We have number of products in market. But if I have the chance to choose one of them I will choose SQL SERVER because…..
- According to the 2005 Survey of Wintercorp, The largest SQL Server DW database is the 19.5 terabytes. It is a database of a European Bank
- High Security. It is offering high level of security.
- Speed and Concurrency, SQL Server 2005 system is able to handle 5,000 transactions per second and 100,000 queries a day and can scale up to 8 million new rows of data per day,
- Finally, more technical peoples are available for SQL SERVER when we compare to any other database.
So that we can say SQL SERVER is more than enough for any type of application.
10. Differences between SQL SERVER 2000 AND 2005?
- 2000: Owner = Schema, hard to remove old users at times Schema is separate.
- 2005: Better granularity in easily controlling security. Logins can be authenticated by certificates.
- 2000: No options built-in, expensive third party options with proprietary skills required to implement properly.
- 2005: Encryption and key management built in.
- 2000: Clustering or Log Shipping requires Enterprise Edition and Expensive hardware.
- 2005: Clustering, Database Mirroring or Log Shipping available in Standard Edition. Database Mirroring can use cheap hardware.
- 2000: Limited to 2GB, 4CPUs in Standard Edition. Limited 64-bit support
- 2005: 4 CPU, no RAM limit in Standard Edition. More 64-bit options offer chances for consolidation.
11. What are the Hotfixes and Patches?
Ans: Hotfixs are software patches that were applied to live i.e. still running systems. A hotfix is a single, cumulative package that includes one or more files that are used to address a problem in a software product (i.e. a software bug).
In a Microsoft SQL SERVER context, hotfixes are small patches designed to address specific issues, most commonly to freshly-discovered security holes.
Ex: If a select query returning duplicate rows with aggregations the result may be wrong….
12. Why Shrink file/ Shrink DB/ Auto Shrink is really bad?
Ans: In the SHRINKFILE command, SQL Server isn’t especially careful about where it puts the pages being moved from the end of the file to open pages towards the beginning of the file.
- The data becomes fragmented, potentially up to 100% fragmentation, this is a performance killer for your database;
- The operation is slow – all pointers to/from the page/rows being moved have to be fixed up, and the SHRINKFILE operation is single-threaded, so it can be really slow (the single-threaded nature of SHRINKFILE is not going to change any time soon)
- Shrink the file by using Truncate Only: First it removes the inactive part of the log and then perform shrink operation
- Rebuild / Reorganize the indexes once the shrink is done so the
Fragmentation level is decreased
13. Which key provides the strongest encryption?
Ans: AES (256 bit)
The longer the key, the better the encryption, so choose longer keys for more encryption. However there is a larger performance penalty for longer keys. DES is a relatively old and weaker algorithm than AES.
AES: Advanced Encryption Standard
DES: Data Encryption Standard
14. What is the difference between memory and disk storage?
Ans: Memory and disk storage both refer to internal storage space in a computer. The term “memory” usually means RAM (Random Access Memory). The terms “disk space” and “storage” usually refer to hard drive storage.
15. What port do you need to open on your server firewall to enable named pipes connections?
Ans: Port 445. Named pipes communicate across TCP port 445.
16. What are the different log files and how to access it?
Ans: SQL Server Error Log: The Error Log, the most important log file, is used to troubleshoot system problems. SQL Server retains backups of the previous six logs, naming each archived log file sequentially. The current error log file is named ERRORLOG. To view the error log, which is located in the %Program-Files%Microsoft SQL ServerMSSQL.1MSSQLLOGERRORLOG directory, open SSMS, expand a server node, expand Management, and click SQL Server Logs
SQL Server Agent Log: SQL Server’s job scheduling subsystem, SQL Server Agent, maintains a set of log files with warning and error messages about the jobs it has run, written to the %ProgramFiles%Microsoft SQL ServerMSSQL.1MSSQLLOG directory. SQL Server will maintain up to nine SQL Server Agent error log files. The current log file is named SQLAGENT.OUT, whereas archived files are numbered sequentially. You can view SQL Server Agent logs by using SQL Server Management Studio (SSMS). Expand a server node, expand Management, click SQL Server Logs, and select the checkbox for SQL Server Agent.
Windows Event Log: An important source of information for troubleshooting SQL Server errors, the Windows Event log contains three useful logs. The application log records events in SQL Server and SQL Server Agent and can be used by SQL Server Integration Services (SSIS) packages. The security log records authentication information, and the system log records service startup and shutdown information. To view the Windows Event log, go to Administrative Tools, Event Viewer.
SQL Server Setup Log: You might already be familiar with the SQL Server Setup log, which is located at %ProgramFiles%Microsoft SQL Server90Setup BootstrapLOGSummary.txt. If the summary.txt log file shows a component failure, you can investigate the root cause by looking at the component’s log, which you’ll find in the %Program-Files%Microsoft SQL Server90Setup BootstrapLOGFiles directory.
SQL Server Profiler Log: SQL Server Profiler, the primary application-tracing tool in SQL Server, captures the system’s current database activity and writes it to a file for later analysis. You can find the Profiler logs in the log .trc file in the %ProgramFiles%Microsoft SQL ServerMSSQL.1MSSQLLOG directory.
17. Explain XP_READERRORLOG or SP_READERRORLOG?
Ans: Xp_readerrorlog or sp_readerrorlog has 7 parameters.
Log_FileNo: -1: All logs
0: Current log file
1: No1 archived log file etc
Log_Type: 1: SQL Server
2: SQL Agent
KeyWord-1: Search for the keyword
KeyWord-2: Search for a combination of Keyword 1 and Keyword 2
Date1 and Date2: Retrieves data between these two dates
‘Asc’/’Desc’: Order the data
EXEC Xp_readerrorlog 0 – Current SQL Server log
EXEC Xp_readerrorlog 0, 1 – Current SQL Server log
EXEC Xp_readerrorlog 0, 2 – Current SQL Agent log
EXEC Xp_readerrorlog -1 – Entire log file
EXEC Xp_readerrorlog 0, 1, ’dbcc’ – Current SQL server log with dbcc in the string
EXEC Xp_readerrorlog 1, 1, ’dbcc’, ’error’ – Archived 1 SQL server log with dbcc and error in the string
EXEC xp_readerrorlog -1, 1, ‘dbcc’, ‘error’, ‘2012-02-21’, ‘2012-02-22′,’desc’
Search entire sql server log file for string ‘dbcc’ and ‘Error’ within the given dates and retrieves in descending order.
Note: Also, to increase the number of log files, add a new registry key “NumErrorLogs” (REG_DWORD) under below location. HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQL.XMSSQLServer By default, this key is absent. Modify the value to the number of logs that you want to maintain.
18. We have 300 SSIS packages those needs to be deployed to production, how can we make it easier / short way to deploy all SSIS packages at once?
Ans: I would store these as XML based files and not in the MSDB database. With the configuration files, you can point the packages from prod to dev (and vice versa) in just a few seconds. The packages and config files are just stored in a directory of your choice. Resources permitting, create a standalone SSIS server away from the primary SQL Server
19. We have a table which is 1.2 GB in size, we need to write an SP which should work with a particular point of time data (like a snapshot) (We should not use snapshot Isolation as it takes other 1.2 TB size)?
Ans: You may want to add insert timestamps and update timestamps for each record. Every time a new record is inserted, stamp it with the DayTime, and also stamp it with the date-time when updated. Also possibly use partitioning to reduce index rebuilds.
20. What is RAID levels? Which one we have to choose for SQL Server user databases?
Ans: Check out the charts in this document. It shows how the disks are setup. It will depend on what the customer wants to spend and level of reliability needed. Raid 5 is common, but see the topic ‘RAID 10 versus RAID 5 in Relational Databases’, in the document below. It’s a good discussion. Raid 10 (pronounced Raid one-zero) is supposed to have the best in terms of performance and reliability, but the cost is higher.
21. How many datafiles I can put in Tempdb? What is the effect of adding multiple data files?
Ans: By far, the most effective configuration is to set tempdb on its own separate fast drive away from the user databases. I would set the number of files based on # of cpu’s divided by 2. So, if you have 8 cpu’s, then set 4 tempdb files. Set the tempdb large enough with 10% data growth. I would start at a general size of 10 GB for each size. I also would not create more than 4 files for each mdf/ldf even if there were more than 8 cpu’s. you can always add more later.
22. Let’s say a user is performing a transaction on a clustered server and failover has occurred. What will happen to the Transaction?
Ans: If it is active/passive, there is a good chance the transaction died, but active/passive is considered by some the better as it is not as difficult to administer. I believe that is what we have on active. Still, active/active may be best depending on what the requirements are for the system.
23. How you do which node is active and which is passive. What are the criteria for deciding the active node?
Ans: Open Cluster Administrator, check the SQL Server group where you can see the current owner. So the current owner is the active node and other nodes are passive.
24. What is the common trace flags used with SQL Server?
Ans: Deadlock Information: 1204, 1205, 1222
Network Database files: 1807
Log Record for Connections: 4013
Skip Startup Stored Procedures: 4022
Disable Locking Hints: 8755
Forces uniform extent allocations instead of mixed page allocations 1118 – (SQL 2005 and 2008) To reduce TempDB contention.
25. Do you know about Resource Database?
Ans: All sys objects are physically stored in resource database and logically available on every database.
Resource database can faster the service packs or upgrades
26. Really does resource faster the upgrades? Can you justify?
Ans: Yes, in earlier versions upgrades requires dropping and recreating system objects now an upgrade requires a copy of the resource file.
We are also capable of rollback the process, because it just needs to overwrite the existing with the older version resource copy.
27. I have my PROD sql server all system db’s are located on E drive and I need my resource db on H drive how can you move it?
Ans: No only resource db cannot be moved, Resource db location is always depends on Master database location, if u want to move resource db you should also move master db.
28. Can we take the backup for Resource DB?
Ans: No way. The only way if you want to get a backup is use windows backup for option resource mdf and ldf files.
29. Any idea what is the Resource dbmdf and ldf file names?
- mssqlsystemresource.mdf and
30. What you do if a column of data type int is out of scope?
Ans: I do alter column to BigInt
31. Are you sure the data type Bigint never been out of scope?
Ans: Yes I am sure.
Let’s take few examples and see how many years will it take for BIGINT to reach its upper limit in a table:
(A) Considering only positive numbers, Max limit of BIGINT = 9,223,372,036,854,775,807
(B) Number of Seconds in a year = 31,536,000
Assume there are 50,000 records inserted per second into the table. Then the number of years it would take to reach the BIGINT max limit is:
9,223,372,036,854,775,807 / 31,536,000 / 50,000 = 5,849,424 years
If we inserted 1 lakh records per second into the table then it would take 2,924,712 yrs
If we inserted 1 million (1000000) records per second into the table then it would take 292,471 yrs
If we inserted 10 million (10000000) records per second into the table then it would take 29,247 yrs
If we inserted 100 million records per second into the table then it would take 2,925 yrs
If we inserted 1000 million records per second into the table then it would take 292 yrs
By this we would have understood that it would take extremely lots of years to reach the max limit of BIGINT.
32. What is the default Port No on which SQL Server listens?
33. What is a system database and what is a user database?
Ans: System databases are the default databases that are installed when the SQL Server is installed. Basically there are 4 system databases: Master, MSDB, TempDB and Model. It is highly recommended that these databases are not modified or altered for smooth functioning of the SQL System.
A user database is a database that we create to store data and start working with the data.
34. What is the importance of a recovery model?
Ans: Primarily, recovery model is chosen keeping in view the amount of data loss one can afford to. If one expects to have minimal or no data loss, choosing the Full recovery model is a good choice. Depending on the recovery model of a database, the behavior of database log file changes. I would recommend you read more material on log backups and log file behavior and so on to understand in depth.
35. What is Replication?
Ans: Replication is a feature in SQL Server that helps us publish database objects and data and copy (replicate) it to one or more destinations. It is often considered as one of the High-Availability options. One of the advantages with Replication is that it can be configured on databases which are in simple recovery model.
36.What the different types of Replication and why are they used?
Ans: There are basically 3 types of replication: Snapshot, Transactional and Merge Replication. The type of Replication you choose, depends on the requirements and/or the goals one is trying to achieve. For example Snapshot Replication is useful only when the data inside the tables does not change frequently and the amount of data is not too large, such as a monthly summary table or a product list table etc. Transactional Replication would useful when maintaining a copy of a transactional table such as sales.
37. What Changes In The Front End Code Is Needed If Mirroring Is Implemented For The High Availability?
Ans: You need to add only FAILOVER PARTNER information in your front end code. “Data Source=ServerA;Failover Partner=ServerB;Initial Catalog=AdventureWorks;Integrated Security=True;”.
38. Where Does The Copy Job Runs In The Log Shipping Primary Or Secondary?
Ans: Secondary server. This question is basically asked to find out whether you have a hands on work on log shipping or not.