Download these FREE Ebooks:
1. Introduction to Digital Marketing
2. Website Planning and Creation
Top SQL Interview Questions
1. Explain the database.
A database is a structured data collection that can be stored, maintained, and retrieved digitally from a local or remote computer system. A fixed design and modelling technique is used to build databases, which can be large and complex. Large databases are housed on computer clusters or cloud storage, whereas smaller databases can be stored on a file system.
2. What are a DBMS and an RDBMS? Give a description of their differences.
A database management system, or DBMS, is a type of system software that allows users to build, access, update, and administer databases. By serving as an interface between the database and its users or application software, it maintains data consistency, makes sure it is organised and ensures that it is easily accessible. The four types of DBMS are as follows:
- Hierarchical Database: It has a tree-like structure, and the information is organised hierarchically. A database's parent can have several children, but a kid can only have one parent.
- Network databases: These types of databases are displayed as graphs with many-to-many relationships, enabling parents to have more than one kid.
- Relational Database: This type of database is the most popular and user-friendly. The values in the columns and rows of the table's representation are related to one another.
- Object-oriented databases: These databases store data as objects with various relationships between them and record data values and processes as objects.
RDBMS maintain data in the form of a number of tables. The common fields between these tables define the relations. Based on RDBMS are MS SQL Server, MySQL, IBM DB2, Oracle, and Amazon Redshift.
DBMS vs RDBMS
Parameters | DBMS | RDBMS |
Access | Data elements need to be accessed separately | Multiple data elements can be accessed at the same time |
Relationship Between Data | No relationship between data | Data in tables are related to each other |
Normalization | It is not present | It is present |
Distributed Database | It does not support distributed database | It supports distributed database |
Data Storage Format | Data is stored in either a navigational or hierarchical form | Data is stored in a tabular structure with headers being the column names and the rows containing corresponding values |
Amount of Data | It deals with a small quantity of data | It deals with a larger amount of data |
Data Redundancy | It is prevalent | Keys and indexes do not allow data redundancy |
Number of Users | It supports a single user | It supports multiple users |
Data Fetching | It is slower for large amounts of data | It is speedy due to the relational approach |
Data Security | Low-security levels when it comes to data manipulation | Multiple levels of data security exist |
Software and Hardware Requirements | Low | High |
Examples | XML, Window Registry, etc. | MySQL, SQL Server, Oracle, Microsoft Access, PostgreSQL, etc. |
3. Describe SQL.
Structured Query Language is known as SQL. It is the preferred language for RDBMS and can be used to manage structured data that has variables or entities with relationships between them. For interacting with databases, SQL is employed.
According to ANSI, SQL is used to manage RDBMS and perform various data manipulation operations on various sorts of data by utilising SQL's characteristics. It functions essentially as a database language for the creation and deletion of databases. It can also be used, among other things, to retrieve and change a table's rows.
4. What are normalization's different forms?
By structuring fields and tables in databases, normalisation helps reduce data reliance and redundancy. It entails building tables and establishing relationships between those tables in accordance with predetermined principles. These criteria can be used to eliminate redundant dependencies and erratic dependencies, allowing normalisation to be more flexible.
The various types of normalisation include:
First Normal Form: A relation is in the first normal form if all of its attributes are single-valued. It violates the first normal form if an attribute is composite or has many values.
Second Normal Form: If a relation satisfies the requirements for the first normal form and does not have any partial dependencies, that is, if it does not contain a non-prime attribute that depends on any suitable subset of any candidate key of the table, it is said to be in the second normal form. Often, a single-column primary key is an answer to this issue.
Third Normal Form: When a relation satisfies the requirements for the second normal form and there is no transitive dependency between the non-prime attributes, all non-prime attributes are determined solely by the candidate keys of the relation and not by other non-prime attributes, a relation is said to be in the third normal form.
Boyce-Codd Normal Form: If a relation satisfies the requirements of the third normal form, it is said to be in the Boyce-Codd normal form (BCNF), and the left-hand side is a super key for each functional dependency. If X is a super key for any nontrivial functional dependency with the form X -> Y, then and only then is a relation in the BCNF.
5. Describe denormalization.
The process of denormalization is the opposite of normalisation; duplicate data is introduced to facilitate the processing of complex queries involving numerous tables that must be combined. Repetitive copies of data are added to or grouped together in an effort to improve the read performance of a database.
6. What do joins in SQL mean?
The join function in SQL is used to merge rows from two or more tables based on a shared column. Depending on how the tables are related to one another, different forms of joins can be utilised to get data.
There are four types of Joins:
Inner Join
Left Join
Right Join
Full Join
7. List the different forms of SQL joins.
SQL Joins come in four different flavours:
(Inner) Join: This method is used to find records in both joined tables that have values that are identical. Most often, queries are joined via an inner join.
Left (Outer) Join: The purpose of a left join is to retrieve all of the records or rows from the left and the matching ones from the right.
Right (Outer) Join: Right join is used to retrieve all the records or rows from the right and the matching ones from the left.\
Full (Outer) Join: This join method is used to find records that match either in the left table or the right table.
8. What subsets of SQL are there?
There are four main categories of SQL queries:
Language for Data Definition (DDL)
- DDL queries, which can be used to define and modify the database's structure, are composed of SQL instructions.
- CREATE schema, databases, and other things are created.
- Drops databases' tables and other items.
- Drops a column from any table structure using the DROP COLUMN command.
- ALTER: Modifies database object definitions
- Removes tables, views, procedures, and other database objects with the TRUNCATE command.
- A COLUMN IS ADDED TO THE TABLE SCHEMA BY USING THIS OPTION.
Language for Data Manipulation (DML)
- These SQL queries are employed to alter database data.
- SELECT INTO: Selects information from one table and adds it to another INSERT: Adds information or records to a table
- UPDATE: Changes the value of any database record.
- DELETE Eliminates data from a table.
- Control Language for Data (DCL)
- These SQL commands control the database's access privileges and permissions.
- GRANT: Provides database objects with access rights.
- REVOKE: Removes authorization from database objects
9. Language for Transaction Control (TCL)
- TCL is a set of commands that fundamentally controls how DML statements and database transactions are handled. TCL enables the creation of logical transactions out of a collection of assertions.
- Commits an irreversible transaction, meaning that it is impossible to recover the database's previous image before the transaction.
- In the event of a mistake, ROLLBACK reverses the stages in a transaction.
- SAVEPOINT: Establishes a transaction savepoint at which a rollback can be carried out.
- STRICT TRANSACTION: Establishes the terms of the transaction.
10. What are some SQL applications?
The principal uses of SQL include:
writing programmes for data integration
establishing and executing analytical queries
retrieving specific data from a database to be used by analytics software and transaction processing
a database's ability to add, update, and remove rows and columns of data
11. An explanation of a DEFAULT constraint
SQL constraints are used to define guidelines for handling data and to restrict the kinds of data that can be entered into tables. Let's learn more about default constraints right now.
When no alternative value is supplied, a default constraint is used to set a column's default value, which is appended to all new records. As an illustration, if we attach a default constraint to the E salary column in the following table and set the default value to 85000, then all entries in this column will have that value by default unless another value was assigned during the insertion.
Let's go over how to create a default constraint now. To begin, let's make a new table and give one of its columns a default constraint.
12. What does "UNIQUE constraint" mean?
To ensure that each value in a column is distinct, use unique constraints. For instance, if we give the e-name column in the following table a unique constraint, then each entry in this column must have a different value.
13. What do the SQL terms "table" and "field" mean?
A table is defined as a collection of rows and columns of ordered data. Simply described, it is a table-formatted collection of connected facts.
The number of columns in a table is referred to as a field, and rows and columns are referred to as tuples and attributes in this context. Fields describe the traits and attributes in the record and hold detailed information about the data.
14. Describe the principal key.
All table records are uniquely identified by a primary key. It must have distinct values and cannot have NULL values. In a table, there can only be one primary key, which is a composite key that can contain one or more fields.
15. What distinguishes the main key from a unique key?
Both primary and unique keys can have distinct values, but only unique keys can have a null value for a primary key. There can only be one primary key per table, however, there can be many unique keys.
16. What is a foreign Key?
An attribute or combination of attributes, that refers to the primary key of another database is known as a foreign key. A foreign key is essentially used to connect two tables.
17. What subsets of SQL are there?
The principal SQL subsets are:
Language for Data Definition (DDL)
Language for Data Manipulation (DML)
Control Language for Data (DCL)
Language for Transaction Control (TCL)
18. Describe the various categories of SQL commands.
DDL: When a database is about to be built, DDL is the section of SQL that defines the database's initial data structure. It is mostly utilised to build and rearrange database objects. DDL commands include:
Create a table and modify it.
Fall table
DML: DML is used to alter data that has already been stored in a database, assisting users in data retrieval and manipulation. It is used to carry out tasks including putting data into the database, updating data, and deleting data from the database using the t, uniseriate, and delete commands.
DCL: The database's data access is managed using DCL. To construct objects linked to user access and manage the allocation of privileges among users, DCL commands are typically employed. In DCL, the commands Grant and Revoke are employed.
TCL: TCL is used to manage the adjustments that DML instructions make. Additionally, it permits the statements to combine with logical transactions. Commit, Rollback, Savepoint, Begin, and Transaction is the commands used in TCL.
19. What applications does SQL have?
Using a SQL database, the following procedures can be carried out:
- Building fresh databases
- Adding fresh data erasing old data
- Updating data retrieving records
- Adding and removing tables
- Creating views and functions
- Changing the data types
20. What is an index?
Indexes facilitate quicker database searches. The SQL Server must scan the entire database and verify each and every row to discover matches if a column in the WHERE clause has no index. This may slow down operations in huge data sets.
Indexes are used to locate all rows that match a specific set of columns, which allows users to quickly search through only those portions of the data for matches.
21. Describe the various index kinds.
Single-column Indexes: Only one column from a table is included in a single-column index.
Composite-column Indexes: For a table with two or more columns, a composite-column index is constructed.
Unique Indexes: A table's data integrity is maintained by using a unique index. Multiple values cannot be entered into a table with a unique index.
22. What are relationships and entities?
Entities: A database can contain information about any identifiable person, place, thing, or other objects.
Employees, projects, salaries, etc., can all be referred to as entities in a company's database, for instance.
Relationships: A link between two tables or entities can be used to describe a relationship between entities.
The student entity and the department entity, for instance, are related to a college database.
23. How would you define data integrity?
The assurance of accuracy and consistency of data across its entire life cycle is known as data integrity. It is a crucial component in the planning, execution, and use of data storage, processing, or retrieval systems.
In order to enforce business rules on data as it is entered into a database or application, data integrity also defines integrity constraints.
24. Describe a data warehouse.
A data warehouse is an organization's huge repository for accumulated data from many different sources. Business decisions are influenced by facts.
25. Why does SQL Server utilise the FLOOR function?
The highest integer value for a given number—which may be equal to or less than the provided number—can be found with the use of the FLOOR() function.
26. Describe the variations between clustered and non-clustered indexes.
Using a clustered index, it is possible to order data rows according to their key values. The information in a clustered index is comparable to a phone book. The information for all Davids is readily available when we open the book at "David" (for "David, Thompson"). The fact that the data are close to one another makes it much easier to retrieve the data using range-based searches. Only one clustered index is possible per table, which is tied to the way the data is stored.
Non-clustered Index: It indexes at one place and stores data in another. Pointers pointing to the data's location are present in the index. There may be numerous non-clustered indexes for a table since the indexes in each one are kept in a distinct location.
27. What are your understandings about CDC in SQL Server?
Change data collection is a CDC term. It records recent SQL Server table INSERT, DELETE, and UPDATE operations. It logs modifications to SQL Server tables in a format that is compatible.
28. What does a database's ACID property mean?
Atomicity, consistency, isolation, and durability make up the acronym ACID. Transaction dependability is checked using ACID characteristics.
Atomicity describes whether a transaction succeeded or failed, with a transaction being a single logical operation on data. This suggests that if one part of a transaction fails, the entire transaction will fail, and the state of the database will not change.
Consistency indicates that the data satisfies all requirements for validity. The status of the transaction is always completed before it exits the database.
Isolation's main goal is concurrency management.
Durability guarantees that a transaction will take place once it is committed, regardless of what transpires in the interim, such as a power outage, a fire, or some other type of disruption.
29. Why are group functions necessary in SQL?
A single result is returned for each group by group functions, which act on a set of rows. Among the most often used group functions are COUNT(), MAX(), MIN(), SUM(), AVG(), and VARIANCE().
30. How do We define AUTO INCREMENT?
When a new record is entered into a table in SQL, AUTOINCREMENT is utilised to generate a unique number automatically.
This primary field is added as the AUTOINCREMENT field so that it is incremented when a new record is inserted because the primary key is unique for each record.
When a new record is inserted, the AUTO-INCREMENT value is automatically increased by 1. It starts at 1.
31. What distinguishes the commands DROP and TRUNCATE?
When a table is deleted, everything connected to it is also deleted. This contains the connections between tables that are specified on the table, the grants and access privileges that the table has, as well as the integrity checks and restrictions.
All the elements related to the table must be redefined in order to build and use it once more in its original form.
There are none of the aforementioned issues if a table is shortened. The table still has its original layout.
32. In SQL, what does "TRIGGER" mean?
The trigger is a process that runs automatically when something happens on the database server. It aids in keeping the table's integrity. When commands like insert, update, and delete are issued, the trigger is set off.
33. In which locations does SQL Server keep usernames and passwords?
Usernames and passwords are kept in SQL Server's main database in the sysxlogins table.
34. What kinds of relationships are there in SQL Server databases?
Linking the columns of two tables together allows for the development of relationships. Relationships can be divided into three categories, which are as follows:
- One-to-one relationship
- one to many relationships
- many to many relationships
35. What kinds of external tools does SQL Server use?
The list of outside resources needed by SQL Server is as follows:
Litespeed 5.0
SQL CHECK,
SQL DOC 2,
SQL Backup 5,
SQL Prompt
36. How may SQL Server expectations be managed?
In SQL Server, exceptions are handled via TRY and CATCH blocks. Put the SQL query in the TRY block, and then write the logic for handling expectations in the CATCH block. The control will immediately move to the CATCH block if the code in the TRY block contains an error.
37. How many different authentication methods does SQL Server support? What exactly are they?
In SQL Server, there are two authentication mechanisms available. As follows:
Windows Authentication Mode: It supports Windows authentication but not SQL Server authentication.
Mixed Mode: It accepts both Windows and SQL Server authentication.
38. What does a SQL Server function do?
An SQL Server database object is a function. In essence, it is a collection of SQL statements that accept input arguments, carry out the processing, and only output results. There is no way to insert, update, or delete records in database tables; functions can only return a single value or table.
39. Describe the various replication types in SQL Server?
Three different replication types are supported in SQL Server:
- Quick replication
- Replication in a transaction
- Fusion of replication
40. Describe SQL Server Agent.
In the daily job of SQL Server administrators or DBAs, SQL Server Agent plays a significant role. One of SQL Server's key components is this. Using a scheduling engine that enables the activities to be completed at predetermined times, the server agent's goal is to implement tasks quickly. Information about planned administration tasks is stored by SQL Server Agent using SQL Server.