Translation of the article was prepared for students of the course "MS SQL Server Developer"
Relational databases are one of the most commonly used databases to this day, and therefore SQL skills for most posts are required. In this article, with SQL questions from interviews, I will introduce you to the most frequently asked questions about SQL (Structured Query Language - Structured Query Language). This article is an ideal guide for exploring all concepts related to SQL, Oracle, MS SQL Server, and the MySQL database.
Our SQL question article is a universal resource with which you can speed up your interview preparation. It consists of a set of 65 of the most common questions that the interviewer can ask during the interview. It usually starts with basic SQL questions and then moves on to more complex ones based on the discussion and your answers. These SQL interview questions will help you get the most value at different levels of understanding.
Let's start!
DELETE | TRUNCATE |
---|---|
Used to delete a row in a table. | Used to delete all rows from a table. |
You can recover data after deletion | You cannot restore data (translation comment: operations are logged differently, but SQL Server has the ability to roll back) transactions) |
DML team | DDL command |
Slower than the TRUNCATE statement | Faster |
Database is a structured data collection. Database Management System (DBMS) - software that interacts with the user, applications and the database itself to collect and analyze data. The DBMS allows the user to interact with the database. The data stored in the database can be modified, retrieved and deleted. They can be of any type, such as strings, numbers, images, etc.
There are two types of DBMS:
A table is an organized data set in the form of rows and columns. A field is a column in a table. For example:
Table: Student_Information
Field: Stu_Id, Stu_Name, Stu_Marks
The JOIN operator is used to join rows from two or more tables based on a column connected between them. It is used to join two tables or get data from there. There are 4 connection types in SQL, namely:
Both Char and Varchar serve as character data types, but varchar is used for variable-length character strings, while Char is used for fixed-length strings. For example, char (10) can only store 10 characters and cannot store a string of any other length, while varchar (10) can store a string of any length up to 10, i.e. e.g. 6, 8, or 2.
_Example: In the Student Stu table, the primary key is.
Constraints are used to indicate restrictions on the data type of a table. They can be specified when creating or modifying a table. Example restrictions:
SQL is the standard Structured Query Language based on English, while MySQL is a database management system. SQL is a relational database language that is used to access and manage data, MySQL is a relational DBMS (database management system), as well as SQL Server, Informix, etc.
Data integrity determines the accuracy as well as the consistency of the data stored in the database. It also defines integrity constraints to enforce business rules for data when they are entered into an application or database.
SQL has a built-in GetDate () function that helps return the current timestamp / date.
There are various types of joins that are used to extract data between tables. Basically, they are divided into four types, namely:
Inner join : In MySQL, the most common type. It is used to return all rows from several tables for which the join condition is fulfilled.
Left Join : in MySQL it is used to return all rows from the left (first) table and only matching rows from the right (second) table for which the join condition is fulfilled.
Right Join : in MySQL it is used to return all rows from the right (second) table and only matching rows from the left (first) table for which the join condition is fulfilled.
Full Join : Returns all records for which there is a match in any of the tables. Therefore, it returns all rows from the left table and all rows from the right table.
Denormalization is a technique that is used to convert from higher to lower normal forms. It helps database developers improve the performance of the entire infrastructure by introducing redundancy into the table. It adds redundant data to the table, given the frequent database queries that combine data from different tables into one table.
Entities: a person, place or object in the real world, data about which can be stored in a database. Tables store data that represents one type of entity. For example, a bank database has a customer table for storing customer information. The customer table stores this information as a set of attributes (columns in the table) for each customer.
Relations: relations or relationships between entities that are somehow related to each other. For example, the customer name is associated with the customer account number and contact information, which may be in the same table. There may also be relationships between individual tables (for example, customer to accounts).
Indexes relate to a performance tuning method that enables faster retrieval of records from a table. The index creates a separate structure for the indexed field and, therefore, allows faster data retrieval.
There are three types of indexes, namely:
Normalization is the process of organizing data, the purpose of which is to avoid duplication and redundancy. Some of the benefits:
The DROP command deletes the table itself, and you cannot make Rollback commands, while the TRUNCATE command deletes all rows from the table ( note translation: in SQL Server, Rollback will normally work and roll back DROP ).
There are many consecutive levels of normalization. These are the so-called normal forms. Each subsequent normal form includes the previous one. The first three normal forms are usually enough.
ACID means Atomicity, Consistency, Isolation, Durability. It is used to provide reliable processing of data transactions in the database system.
Atomicity. Ensures that the transaction is fully completed or fails, where the transaction represents a single logical data operation. This means that if one part of any transaction fails, the entire transaction fails and the state of the database remains unchanged.
Coherence. Ensures that data must comply with all validation rules. Simply put, you can say that your transaction will never leave your database in an invalid state.
Isolation. The main purpose of isolation is to control the mechanism of parallel data changes.
Durability. Durability implies that if the transaction was confirmed (COMMIT), the changes that occurred within the transaction will be preserved regardless of what might get in their way (for example, power loss, failure or errors of any kind).
A trigger in SQL is a special type of stored procedure that is designed to be automatically executed when or after data changes. This allows you to execute a code package when an insert, update, or any other query is performed on a specific table.
Three types of statements are available in SQL, namely:
The value NULL is not at all equal to zero or a space. A NULL value represents a value that is not available, unknown, assigned, or not applicable, while zero is a number and space is a character.
A cross join creates a cross or Cartesian product of two tables, while a natural join is based on all columns that have the same name and data types in both tables.
A subquery is a query inside another query that defines a query to retrieve data or information from a database. In a subquery, the outer query is called the main query, while the inner query is called the subquery. Subqueries are always executed first, and the result of the subquery is passed to the main query. It can be nested in SELECT, UPDATE, or any other query. A subquery can also use any comparison operator, such as>, <, or =.
There are two types of subqueries, namely: correlated and uncorrelated.
To count the number of records in a table, you can use the following commands:SELECT * FROM table1
SELECT COUNT(*) FROM table1
SELECT rows FROM sysindexes WHERE id = OBJECT_ID(table1) AND indid < 2
We will publish another 35 questions with answers in the next part ... Follow the news!
Source: https://habr.com/ru/post/461067/
All Articles