SQL Server Interview Questions and Answers
SQL Server is based on client-server architectural model in which there is a Server (having the Database) which is shared or accessed by several Users with the help of client applications. SQL server could be defined as A client or server RDBMS (Relational Database Management System) based on a programming language known as Structured Query Language (SQL)
SQL Server is divided into two main engines: the Relational Engine and the Storage Engine. The Relational Engine contains below components: The Storage Engine contains below components: There are basically two types of indexes that we use with the SQL Server. Clustered and the Non-Clustered. This command is basically used when we do a large processing of data. If we do a large amount of deletions any modification or Bulk Copy into the tables, we need to basically update the indexes to take these changes into account. UPDATE_STATISTICS updates the indexes on these tables accordingly. Locking in SQL Server is used to manage concurrent access to data and ensure data integrity. The process involves: The transaction log in SQL Server plays a crucial role in ensuring data durability and recoverability. Its functions include: SQL Server uses a buffer pool and memory manager to efficiently manage memory resources. Key points include: SQL Server runs on port 1433 but we can also change it for better security. From the Network Utility TCP/IP properties –> Port number.both on client and the server. DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation task and status checks. (Database consistency check) – DBCC CHECKDB – Ensures that tables in the db and the indexes are correctly linked.and DBCC CHECKALLOC – To check that all pages in a db are correctly allocated. DBCC SQLPERF – It gives report on current usage of transaction log in percentage. DBCC CHECKFILEGROUP – Checks all tables file group for any damage. sp_renamedb ‘oldname’ , ‘newname’ Well sometimes sp_reanmedb may not work you know because if someone is using the db it will not accept this command so what do you think you can do in such cases? In such cases we can first bring to db to single user using sp_dboptions and then we can rename that db and then we can rerun the sp_dboptions command to remove the single user mode. Join actually puts data from two or more tables into a single result set. There are three types of joins: Inner Join, Outer Join, Cross Join SQL Profiler utility allows us to basically track connections to the SQL Server and also determine activities such as which SQL Scripts are running, failed jobs etc. Linked Servers is a concept in SQL Server by which we can add other SQL Server to a Group and query both the SQL Server dbs using T-SQL Statements. We can link any server provided we have the OLE-DB provider from Microsoft to allow a link. For Oracle we have a OLE-DB provider for oracle that microsoft provides to add it as a linked server to the sql server group. sp_addlinkedserver, sp_addlinkedsrvlogin MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator) SQL SERVER – is for running the databases SQL AGENT – is for automation such as Jobs, DB Maintanance, Backups DTC – Is for linking and connecting to other SQL Servers First check the processor and memory usage to see that processor is not above 80% utilization and memory not above 40-45% utilization then check the disk utilization using Performance Monitor, Secondly, use SQL Profiler to check for the users and current SQL activities and jobs running which might be a problem. Third would be to run UPDATE_STATISTICS command to update the indexes Lets say due to N/W or Security issues client is not able to connect to server or vice versa. First I will look to ensure that port settings are proper on server and client Network utility for connections. ODBC is properly configured at client end for connection ——Makepipe & readpipe are utilities to check for connection. Makepipe is run on Server and readpipe on client to check for any connection issues. Windows mode and mixed mode (SQL & Windows). They get stored in master db in the sysxlogins table. Logshipping is a new feature of SQL Server 2000. We should have two SQL Server – Enterprise Editions. From Enterprise Manager we can configure the logshipping. In logshipping the transactional log file from one server is automatically updated into the backup database on the other server. If one server fails, the other server will have the same db and we can use this as the DR (disaster recovery) plan. For restoring the master db we have to stop the SQL Server first and then from command line we can type SQLSERVER –m which will basically bring it into the maintenance mode after which we can restore the master db. Bulk Copy is a tool used to copy huge amount of data from tables and views. But it won’t copy the structures of the same. We have to write some DTS packages for it. RAID stands for Redundant Array of Independent Disks. RAID defines data storage schemes to divide and replicate data among various disks so that data reliability and I/O performance can be increased. The basic configurations of RAID are: LEVEL 0: Striped set without parity/Non-Redundant Array LEVEL 1: Mirrored set without parity LEVEL 2: Redundancy through hamming code LEVEL 3: Striped set with dedicated parity/Bit interleaved parity LEVEL 4: Block level parity LEVEL 5: Striped set with distributed parity LEVEL 6: Striped set with dual distributed Parity Database architecture describes the design of the database. It explains how the data is stored. The data of the server is stored in databases. This database is further split into one or more discs. The database can be considered to have two layers. Physical layer, which is a transparent layer for the database administrators to work on. Other users typically work on the user view layer. Tables, views, procedures form this view A page is a unit of data storage in SQL. The size of a page is 8Kb. A page has a header and a body. Different types of pages are: Date, text, index, page free space etc. The data rows are put on the page serially after the header. Extents are units in which space is allocated to tables and indexes. An extent is 8 continuous pages. SQL Server has two types of extents: uniform and mixed extent. For efficient allocation, the SQL server does not allocate whole extents to tables with small amounts of data The system database contains information/metadata for all database present on an SQL Server instance. The system database stores information regarding logins, configuration settings, connected servers etc. It also holds various extended stored procedures to access external processes and applications. Major system databases: Master: Core system database to mange Sql Server instance. Resource: Responsible for physically storing all system objects. TempDB: This is a temporary database used to store temporary, tables, cursors, indexes, variables etc. Model: This acts as a template database for all user created databases. MSDB: Database to manage SQL Server agent configurations. Distribution: Database primarily used for SQL Server replication. ReportServer: Main database for reporting services to store metadata and other object definitions. ReportServerTempDB: Acts as a temporary storage for reporting services. When there is not enough room on a page for a new row, a Server splits the page, allocates a new page, and moves some rows to the new page Database objects such as tables, primary key, and foreign key describe the structure of the content of a database. These objects also represent the properties of a server. Server side objects are objects that reside on the server but not in the database. Typical examples of server side objects include, logins, user defined error messages etc. The database objects are contained in the database project while the server objects are contained in the server project. These objects are defined in a .sql file. Most of these objects are defined in a separate file depending on the scenario. E.g it is necessary to specify columns in the same file where the table is defined The physical database architecture describes how the database and files are organized in a SQL server. Pages and extents: these describe how the data is stored Physical Database Files and File groups: describes the operating system files used to store data and logs. Space Allocation and Reuse: Describes the algorithms used for space allocation. Table and Index Architecture: Describes the way pages for tables can be indexed Can you define Model Database It is a template database used in the creation of new database. The logical components are usually used to connect to the database. Any object that a user can use to access or connect to the database is a logical component. Triggers, tables, procedures, views, keys etc are typical examples The physical database architecture describes how the database and files are organized in a SQL server. Pages and extents: these describe how the data is stored Physical Database Files and File groups: describes the operating system files used to store data and logs. Space Allocation and Reuse: Describes the algorithms used for space allocation. Table and Index Architecture: Describes the way pages for tables can be indexed Scheduler (SOS Scheduler): The object that manages thread scheduling in SQL Server and allows threads to be exposed to the CPU (described in sys.dm_os_schedulers). This is the all-powerful but benign and graceful master whom everyone abides. He does not control things but lets the workers work with each other and relies on their cooperation (co-operative scheduling mode). Each scheduler /master (one per logical CPU) accepts new tasks and hands them off to workers. SOS Scheduler allows one worker at a time to be exposed to the CPU. Request: Request is the logical representation of a query request made from the client application to SQL Server (sys.dm_exec_requests). This query request has been assigned to a task that the scheduler hands off to a worker to process. This represents query requests as well as system thread operations (like checkpoint, log writer, etc); you will not find login, logouts, attentions and the like here. Also, note that this is a representation at the SQL execution engine level (thus dm_EXEC_requests) not at the SOS Scheduler layer. Session: When the client application connects to SQL Server the two sides establish a “session” on which to exchange information. Strictly speaking a session is not the same as the underlying physical connection; it is a SQL Server logical representation of a connection. But for practical purposes, you can think of this as being a connection (session =~ connection). See sys.dm_exec_sessions. This is the old SPID that existed in SQL Server 2000 and earlier. You may sometimes notice a single session repeating multiple times in a DMV output. This happens because of parallel queries. A parallel query uses the same session to communicate with the client, but on the SQL Server side multiple worker (threads) are assigned to service this request. So if you see multiple rows with the same session ID, know that the query request is being serviced by multiple threads. Connection: This is the actual physical connection established at the lower protocol level with all of its characteristics sys.dm_exec_connections . There is a 1:1 mapping between a Session and a Connection It stores temporary objects like temporary tables and temporary stored procedure. CUBE generates a result set that represents aggregates for all combinations of values in the selected columns. ROLLUP generates a result set that represents aggregates for a hierarchy of values in the selected columns. It stores information related to database backups, DTS packages, Replication, SQL Agent information, SQL Server jobs. SQL Server Network Interface (SNI) is a protocol layer that establishes the network connection between the client and the server. It consists of a set of APIs that are used by both the database engine and the SQL Server Native Client (SNAC). SQL Server has support for the following protocols: Shared memory TCP/IP Named Pipes VIA — Virtual Interface Adapter Master database is system database. It contains information about server’s configuration. It is a very important database and important to backup Master database. Without Master database, server can’t be started.Can you explain SQL server?
What are the types of indexes available with SQL Server?
When do we use the UPDATE_STATISTICS command?
Explain the architecture of SQL Server?
The architecture of SQL Server consists of the following components:
What is the role of the SQL Server Query Optimizer?
Explain the process of locking in SQL Server.
What is the role of the transaction log in SQL Server?
How does SQL Server handle memory management?
Which TCP/IP port does SQL Server run on?
From where can you change the default port?
What is the use of DBCC commands?
Can you give me some DBCC command options?
What command do we use to rename a db?
What is a Join in SQL Server?
Can you explain the types of Joins that we can have with Sql Server?
When do you use SQL Profiler?
Can you define Linked Server?
Can you link only other SQL Servers or any database servers such as Oracle?
Which stored procedure will you be running to add a linked server?
What are the OS services that the SQL Server installation adds?
Can you explain the role of each service?
How do you troubleshoot SQL Server if its running very slow?
How do you troubleshoot?
What are the authentication modes in SQL Server?
Where do you think the user’s names and passwords will be stored in sql server?
Can you define log shipping? Can we do log shipping with SQL Server 7.0
Let us say the SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
Can you define BCP? When do we use it?
What should we do to copy the tables, schema and views from one SQL Server to another?
Can you define RAID and what are different types of RAID configurations?
Can you explain database architecture?
What are pages and Extents?
Can you explain system database?
What are Page Splits?
Can you explain what are the database objects?
Can you explain Illustrate physical database architecture?
Can you explain logical database components
Please illustrate physical database architecture?
Can you explain Scheduler, Request, Session, Connection in SQL Server architecture?
Can you define TEMPDB Database?
What is the difference between CUBE operator and ROLLUP operator?
Can you define MSDB Database?
What is SNI Protocol Layer?
Do you know what the restrictions applicable while creating views are?
Can you explain Master Database?
Related posts:
- CouchDB Interview Questions and Answers
- DBMS Interview Questions and Answers
- MongoDB Interview Questions and Answers
- MySQL Interview Questions & Answers
- PL/SQL Interview Questions and Answers
- SQL Server 2008 Interview Questions and Answers
- SQL Server Interview Questions and Answers
- SQLite Interview Questions and Answers