Can you explain SQL server?
SQL Server is divided into two main engines: the Relational Engine and the Storage Engine.
The Relational Engine contains below components:
- CMD Parser
- Optimizer
- Query Executor
The Storage Engine contains below components:
- Access Methods code
- Buffer Manager
- Transaction Manager
What are the types of indexes available with SQL Server?
There are basically two types of indexes that we use with the SQL Server. Clustered and the Non-Clustered.
When do we use the UPDATE_STATISTICS command?
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.
Explain the architecture of SQL Server?
The architecture of SQL Server consists of the following components:
- Client Application: The application or tool used to connect and interact with SQL Server.
- Client Network Library: Handles the communication between the client application and SQL Server.
- SQL Server Instance: The installation of SQL Server on a machine, which includes multiple components like the Database Engine, SQL Server Agent, Analysis Services, etc.
- Database Engine: The core component that manages the storage, processing, and retrieval of data. It includes the SQL Server Database Management System (DBMS), query optimizer, buffer pool, and other modules.
- Storage Engine: Responsible for managing the physical storage of data on disk, including data files, transaction log files, and indexes.
- SQL Server Agent: Handles automation tasks, job scheduling, and alerts.
- SQL Server Data Tools (SSDT): Provides an integrated development environment for database development and management.
- Integration Services (SSIS): Handles data integration and transformation tasks.
- Analysis Services (SSAS): Supports online analytical processing (OLAP) and data mining capabilities.
- Reporting Services (SSRS): Enables the creation, management, and delivery of reports.
What is the role of the SQL Server Query Optimizer?
- The SQL Server Query Optimizer is responsible for generating an optimal execution plan for queries. Its main tasks include:
- Parsing and validating the SQL query.
- Analyzing available indexes, statistics, and table structures.
- Evaluating different execution plans and estimating their costs.
- Selecting the plan with the lowest cost based on statistics and cost estimations.
- Generating the execution plan that will be used by the SQL Server Database Engine to execute the query efficiently.
Explain the process of locking in SQL Server.
Locking in SQL Server is used to manage concurrent access to data and ensure data integrity. The process involves:
- When a transaction accesses a resource (e.g., a table or a row), it requests a lock on that resource.
- SQL Server grants an appropriate lock mode (e.g., shared lock, exclusive lock) based on the transaction isolation level and the requested lock mode.
- Locks can be held for the duration of a transaction or for a shorter period, depending on the lock type and the transaction requirements.
- Other transactions attempting to access the same resource are either blocked (if an incompatible lock is held) or granted a compatible lock.
- After a transaction completes, the locks are released to allow other transactions to access the resource.
What is the role of the transaction log in SQL Server?
The transaction log in SQL Server plays a crucial role in ensuring data durability and recoverability. Its functions include:
- Recording all modifications made to the database, including data modifications, schema changes, and transactional details.
- Providing the ability to recover the database to a consistent state in the event of a system failure or data corruption.
- Facilitating transactional rollback or rollback of individual statements within a transaction.
- Supporting high availability features like database mirroring, Always On Availability Groups, and log shipping.
How does SQL Server handle memory management?
SQL Server uses a buffer pool and memory manager to efficiently manage memory resources. Key points include:
- The buffer pool is a portion of memory where SQL Server caches data pages from the database to reduce disk I/O.
- The memory manager allocates memory to various components like query plans, execution contexts, locks, and caches.
- SQL Server uses a combination of dynamic memory management and configuration settings to control memory allocation.
- Memory allocation and deallocation are based on demand and can be adjusted dynamically to optimize performance.
Which TCP/IP port does SQL Server run on?
SQL Server runs on port 1433 but we can also change it for better security.
From where can you change the default port?
From the Network Utility TCP/IP properties –> Port number.both on client and the server.
What is the use of DBCC commands?
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.
Can you give me some DBCC command options?
(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.
What command do we use to rename a db?
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.
What is a Join in SQL Server?
Join actually puts data from two or more tables into a single result set.
Can you explain the types of Joins that we can have with Sql Server?
There are three types of joins: Inner Join, Outer Join, Cross Join
When do you use SQL Profiler?
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.
Can you define Linked Server?
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.
Can you link only other SQL Servers or any database servers such as Oracle?
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.
Which stored procedure will you be running to add a linked server?
sp_addlinkedserver, sp_addlinkedsrvlogin
What are the OS services that the SQL Server installation adds?
MS SQL SERVER SERVICE, SQL AGENT SERVICE, DTC (Distribution transac co-ordinator)
Can you explain the role of each service?
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
How do you troubleshoot SQL Server if its running very slow?
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.
How do you troubleshoot?
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.
What are the authentication modes in SQL Server?
Windows mode and mixed mode (SQL & Windows).
Where do you think the user’s names and passwords will be stored in sql server?
They get stored in master db in the sysxlogins table.
Can you define log shipping? Can we do log shipping with SQL Server 7.0
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.
Let us say the SQL Server crashed and you are rebuilding the databases including the master database what procedure to you follow?
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.
Can you define BCP? When do we use it?
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.
What should we do to copy the tables, schema and views from one SQL Server to another?
We have to write some DTS packages for it.
Can you define RAID and what are different types of RAID configurations?
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
Can you explain database architecture?
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
What are pages and Extents?
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
Can you explain system database?
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.
What are Page Splits?
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
Can you explain what are the database objects?
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
Can you explain Illustrate physical database architecture?
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.
Can you explain logical database components
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
Please illustrate physical database architecture?
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 explain Scheduler, Request, Session, Connection in SQL Server architecture?
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
Can you define TEMPDB Database?
It stores temporary objects like temporary tables and temporary stored procedure.
What is the difference between CUBE operator and ROLLUP operator?
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.
Can you define MSDB Database?
It stores information related to database backups, DTS packages, Replication, SQL Agent information, SQL Server jobs.
What is SNI Protocol Layer?
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
Do you know what the restrictions applicable while creating views are?
- Views can be created referencing tables and views only in the current database.
- A view name must not be the same as any table owned by that user.
- You can build views on other views and on procedures that reference views.
- Rules or DEFAULT definitions can’t be associated with views.
- Only INSTEAD OF triggers can be associated with views.
- The query that defines the view cannot include the ORDER BY, COMPUTE, or COMPUTE BY clauses or the INTO keyword.
- You cannot define full-text index definitions for views.
- You cannot create temporary views
- You cannot create views on temporary tables.
Can you explain Master Database?
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.