{"id":1483,"date":"2023-12-12T13:45:57","date_gmt":"2023-12-12T13:45:57","guid":{"rendered":"https:\/\/www.kaashivinfotech.com\/blog\/?p=1483"},"modified":"2026-06-06T12:31:44","modified_gmt":"2026-06-06T12:31:44","slug":"basic-sql-interview-questions","status":"publish","type":"post","link":"https:\/\/www.kaashivinfotech.com\/blog\/basic-sql-interview-questions\/","title":{"rendered":"Basic SQL Interview Questions &#038; Answers [Updated]"},"content":{"rendered":"<p data-pm-slice=\"1 1 []\">If you&#8217;re preparing for your next tech interview, mastering the <a href=\"https:\/\/www.wikitechy.com\/interview-questions\/category\/sql\/\" target=\"_blank\" rel=\"noopener\"><strong>basic SQL interview questions<\/strong><\/a>\u00a0is crucial.<\/p>\n<p>SQL, or Structured Query Language, is a powerful and standardized programming language designed for managing and manipulating relational databases. It serves as a means to interact with databases, enabling users to create, retrieve, update, and delete data. SQL is widely used in various industries for tasks ranging from simple data queries to complex database management and administration.<\/p>\n<p>Databases, organized in a tabular format, store information that can be easily accessed and managed using SQL. SQL provides a set of commands that allow users to interact with the database, making it a fundamental skill for anyone working with data or involved in software development.<\/p>\n<p>These questions cover some fundamental aspects of SQL and are commonly asked in interviews to assess a candidate&#8217;s understanding of database management and SQL syntax.<\/p>\n<h1>Basic SQL interview questions and answers<\/h1>\n<figure id=\"attachment_8663\" aria-describedby=\"caption-attachment-8663\" style=\"width: 1024px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-8663\" src=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers.png\" alt=\"basic sql interview questions\" width=\"1024\" height=\"1024\" srcset=\"https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers.png 1024w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-300x300.png 300w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-150x150.png 150w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-768x768.png 768w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-72x72.png 72w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-144x144.png 144w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-332x332.png 332w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-664x664.png 664w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-688x688.png 688w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-24x24.png 24w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-48x48.png 48w, https:\/\/www.kaashivinfotech.com\/blog\/wp-content\/uploads\/2023\/12\/Basic-SQL-Questions-and-Answers-96x96.png 96w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption id=\"caption-attachment-8663\" class=\"wp-caption-text\">50+ Basic SQL Questions and Answers<\/figcaption><\/figure>\n<h3><strong>What is SQL?<\/strong><\/h3>\n<p>SQL (Structured Query Language) is a standard language used to access and manipulate relational databases. It allows users to perform tasks like retrieving, inserting, updating, and deleting data.<\/p>\n<h3><strong>What are the different types of SQL commands?<\/strong><\/h3>\n<ul>\n<li>SQL commands are categorized as:<\/li>\n<li>DDL (Data Definition Language): CREATE, ALTER, DROP<\/li>\n<li>DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE<\/li>\n<li>DCL (Data Control Language): GRANT, REVOKE<\/li>\n<li>TCL (Transaction Control Language): COMMIT, ROLLBACK, SAVEPOINT<\/li>\n<\/ul>\n<h3><strong>What is a primary key in SQL?<\/strong><\/h3>\n<p>A primary key uniquely identifies each row in a table. It must contain unique values and cannot have NULLs. Each table can have only one primary key.<\/p>\n<h3><strong>What is a foreign key?<\/strong><\/h3>\n<p>A foreign key is a field in one table that refers to the primary key in another. It establishes a link between the two tables and maintains referential integrity.<\/p>\n<h3><strong>What is the difference between WHERE and HAVING clause?<\/strong><\/h3>\n<ul>\n<li>WHERE filters rows before aggregation.<\/li>\n<li>HAVING filters groups after aggregation.<\/li>\n<\/ul>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SELECT department, COUNT(*) <br\/>FROM employees <br\/>GROUP BY department <br\/>HAVING COUNT(*) &gt; 5;<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<h3><strong>What are joins in SQL? Name the types.<\/strong><\/h3>\n<p>Joins combine rows from two or more tables. Types include:<\/p>\n<ul>\n<li>INNER JOIN<\/li>\n<li>LEFT JOIN<\/li>\n<li>RIGHT JOIN<\/li>\n<li>FULL OUTER JOIN<\/li>\n<li>CROSS JOIN<\/li>\n<li>SELF JOIN<\/li>\n<\/ul>\n<h3><strong>What is an INNER JOIN?<\/strong><\/h3>\n<p>It returns only the matching rows from both tables.<\/p>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SELECT e.name, d.dept_name <br\/>FROM employees e <br\/>INNER JOIN departments d <br\/>ON e.dept_id = d.id;<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<h3><strong>What is normalization?<\/strong><\/h3>\n<ul>\n<li>Normalization is the process of organizing data to minimize redundancy and dependency. Common normal forms include 1NF, 2NF, 3NF, and BCNF.<\/li>\n<\/ul>\n<p data-start=\"399\" data-end=\"433\"><strong data-start=\"406\" data-end=\"433\">Goals of Normalization:<\/strong><\/p>\n<ul data-start=\"434\" data-end=\"553\">\n<li data-start=\"434\" data-end=\"473\">\n<p data-start=\"436\" data-end=\"473\">Eliminate redundant (duplicate) data.<\/p>\n<\/li>\n<li data-start=\"474\" data-end=\"512\">\n<p data-start=\"476\" data-end=\"512\">Ensure data dependencies make sense.<\/p>\n<\/li>\n<li data-start=\"513\" data-end=\"553\">\n<p data-start=\"515\" data-end=\"553\">Simplify data maintenance and updates.<\/p>\n<\/li>\n<\/ul>\n<h3><strong>What is denormalization?<\/strong><\/h3>\n<p data-start=\"0\" data-end=\"349\"><strong data-start=\"0\" data-end=\"19\">Denormalization<\/strong> is the process of <strong data-start=\"38\" data-end=\"80\">introducing redundancy into a database<\/strong> by <strong data-start=\"84\" data-end=\"104\">combining tables<\/strong> or <strong data-start=\"108\" data-end=\"134\">adding duplicated data<\/strong>, which was originally removed during <strong data-start=\"172\" data-end=\"189\">normalization<\/strong>. It is typically done to <strong data-start=\"215\" data-end=\"243\">improve read performance<\/strong> and <strong data-start=\"248\" data-end=\"276\">speed up complex queries<\/strong>, especially in <strong data-start=\"292\" data-end=\"316\">relational databases<\/strong> used for analytics or reporting.<\/p>\n<h3><strong>What is a constraint?<\/strong><\/h3>\n<p>Constraints enforce rules on data columns. Types include:<\/p>\n<ul>\n<li>NOT NULL<\/li>\n<li>UNIQUE<\/li>\n<li>CHECK<\/li>\n<li>DEFAULT<\/li>\n<li>PRIMARY KEY<\/li>\n<li>FOREIGN KEY<\/li>\n<\/ul>\n<h3><strong>Difference between DELETE, TRUNCATE, and DROP?<\/strong><\/h3>\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"2805\" data-end=\"3075\">\n<thead data-start=\"2805\" data-end=\"2873\">\n<tr data-start=\"2805\" data-end=\"2873\">\n<th data-start=\"2805\" data-end=\"2816\" data-col-size=\"sm\">Command<\/th>\n<th data-start=\"2816\" data-end=\"2831\" data-col-size=\"sm\">Deletes Data<\/th>\n<th data-start=\"2831\" data-end=\"2846\" data-col-size=\"sm\">Can Rollback<\/th>\n<th data-start=\"2846\" data-end=\"2873\" data-col-size=\"sm\">Deletes Table Structure<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"2944\" data-end=\"3075\">\n<tr data-start=\"2944\" data-end=\"2989\">\n<td data-start=\"2944\" data-end=\"2955\" data-col-size=\"sm\">DELETE<\/td>\n<td data-col-size=\"sm\" data-start=\"2955\" data-end=\"2977\">Yes (specific rows)<\/td>\n<td data-col-size=\"sm\" data-start=\"2977\" data-end=\"2983\">Yes<\/td>\n<td data-col-size=\"sm\" data-start=\"2983\" data-end=\"2989\">No<\/td>\n<\/tr>\n<tr data-start=\"2990\" data-end=\"3030\">\n<td data-start=\"2990\" data-end=\"3001\" data-col-size=\"sm\">TRUNCATE<\/td>\n<td data-col-size=\"sm\" data-start=\"3001\" data-end=\"3018\">Yes (all rows)<\/td>\n<td data-col-size=\"sm\" data-start=\"3018\" data-end=\"3024\">No<\/td>\n<td data-col-size=\"sm\" data-start=\"3024\" data-end=\"3030\">No<\/td>\n<\/tr>\n<tr data-start=\"3031\" data-end=\"3075\">\n<td data-start=\"3031\" data-end=\"3042\" data-col-size=\"sm\">DROP<\/td>\n<td data-col-size=\"sm\" data-start=\"3042\" data-end=\"3063\">Yes (entire table)<\/td>\n<td data-col-size=\"sm\" data-start=\"3063\" data-end=\"3068\">No<\/td>\n<td data-col-size=\"sm\" data-start=\"3068\" data-end=\"3075\">Yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong>What is a View in SQL?<\/strong><\/h3>\n<p>A <strong data-start=\"34\" data-end=\"42\">View<\/strong> in SQL is a <strong data-start=\"55\" data-end=\"72\">virtual table<\/strong> based on the result of a <strong data-start=\"98\" data-end=\"122\">predefined SQL query<\/strong>. It does <strong data-start=\"132\" data-end=\"161\">not store data physically<\/strong>, but instead presents data from one or more underlying tables in a customized format. Think of a view as a <strong data-start=\"269\" data-end=\"299\">saved SQL SELECT statement<\/strong> that you can treat like a table.<\/p>\n<h3><strong>How to fetch the second highest salary?<\/strong><\/h3>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SELECT MAX(salary) <br\/>FROM employees <br\/>WHERE salary &lt; (SELECT MAX(salary) FROM employees);<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<h3>What is an Index in SQL?<\/h3>\n<p data-start=\"32\" data-end=\"266\">An <strong data-start=\"35\" data-end=\"51\">Index in SQL<\/strong> is a <strong data-start=\"57\" data-end=\"76\">database object<\/strong> that helps <strong data-start=\"88\" data-end=\"122\">speed up the retrieval of rows<\/strong> from a table. Think of it like an <strong data-start=\"157\" data-end=\"176\">index in a book<\/strong> \u2013 instead of reading the whole book to find a topic, you go straight to the indexed page.<\/p>\n<p data-start=\"32\" data-end=\"266\">SQL Syntax to Create an Index:<\/p>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">CREATE INDEX idx_customer_name<br\/>ON Customers (CustomerName);<br\/><br\/>CREATE CLUSTERED INDEX idx_customer_id<br\/>ON Customers (CustomerID);<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<h3><strong>What is a subquery?<\/strong><\/h3>\n<p>A <strong data-start=\"2\" data-end=\"14\">subquery<\/strong> (also known as a <strong data-start=\"32\" data-end=\"48\">nested query<\/strong> or <strong data-start=\"52\" data-end=\"67\">inner query<\/strong>) is a SQL query embedded inside another query. It is used to perform operations that depend on the results of another query.<\/p>\n<p data-start=\"1015\" data-end=\"1042\"><strong>Types of Subqueries:<\/strong><\/p>\n<ul data-start=\"1043\" data-end=\"1253\">\n<li data-start=\"1043\" data-end=\"1087\">\n<p data-start=\"1046\" data-end=\"1087\"><strong data-start=\"1046\" data-end=\"1069\">Single-row subquery<\/strong> \u2013 returns one row<\/p>\n<\/li>\n<li data-start=\"1088\" data-end=\"1137\">\n<p data-start=\"1091\" data-end=\"1137\"><strong data-start=\"1091\" data-end=\"1113\">Multi-row subquery<\/strong> \u2013 returns multiple rows<\/p>\n<\/li>\n<li data-start=\"1138\" data-end=\"1199\">\n<p data-start=\"1141\" data-end=\"1199\"><strong data-start=\"1141\" data-end=\"1164\">Correlated subquery<\/strong> \u2013 uses values from the outer query<\/p>\n<\/li>\n<li data-start=\"1200\" data-end=\"1253\">\n<p data-start=\"1203\" data-end=\"1253\"><strong data-start=\"1203\" data-end=\"1222\">Nested subquery<\/strong> \u2013 subqueries within subqueries<\/p>\n<\/li>\n<\/ul>\n<h3><strong>Difference between CHAR and VARCHAR?<\/strong><\/h3>\n<p>The <strong data-start=\"4\" data-end=\"47\">difference between <code class=\"\" data-line=\"\">CHAR<\/code> and <code class=\"\" data-line=\"\">VARCHAR<\/code><\/strong> in SQL lies mainly in how they store data and handle storage space<\/p>\n<table>\n<thead>\n<tr>\n<th>Feature<\/th>\n<th><code class=\"\" data-line=\"\">CHAR<\/code><\/th>\n<th><code class=\"\" data-line=\"\">VARCHAR<\/code><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Length Type<\/td>\n<td>Fixed<\/td>\n<td>Variable<\/td>\n<\/tr>\n<tr>\n<td>Padding<\/td>\n<td>Padded with spaces<\/td>\n<td>No padding<\/td>\n<\/tr>\n<tr>\n<td>Storage Efficiency<\/td>\n<td>Less efficient for short values<\/td>\n<td>More efficient for varying lengths<\/td>\n<\/tr>\n<tr>\n<td>Performance<\/td>\n<td>Slightly faster for fixed-size data<\/td>\n<td>May be slower due to size calculation<\/td>\n<\/tr>\n<tr>\n<td>Use Case<\/td>\n<td>IDs, codes, fixed-length values<\/td>\n<td>Names, emails, descriptions<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong>How to find duplicates?<\/strong><\/h3>\n<p data-start=\"0\" data-end=\"173\">To <strong data-start=\"3\" data-end=\"29\">find duplicates in SQL<\/strong>, you typically use the <code class=\"\" data-line=\"\">GROUP BY<\/code> clause along with the <code class=\"\" data-line=\"\">HAVING<\/code> clause to identify rows that occur more than once based on specific column(s).<\/p>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SELECT column_name, COUNT(*) <br\/>FROM table_name <br\/>GROUP BY column_name <br\/>HAVING COUNT(*) &gt; 1;<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<h3><strong>What is a Trigger?<\/strong><\/h3>\n<p data-start=\"24\" data-end=\"220\">A <strong data-start=\"26\" data-end=\"37\">Trigger<\/strong> in SQL (Structured Query Language) is a <strong data-start=\"78\" data-end=\"114\">special kind of stored procedure<\/strong> that <strong data-start=\"120\" data-end=\"159\">automatically executes (or &#8220;fires&#8221;)<\/strong> in response to certain events on a particular table or view.<\/p>\n<h4 data-start=\"222\" data-end=\"267\">\ud83d\udd39 Common Events that Trigger a Trigger:<\/h4>\n<ul data-start=\"268\" data-end=\"378\">\n<li data-start=\"268\" data-end=\"305\">\n<p data-start=\"270\" data-end=\"305\"><code class=\"\" data-line=\"\">INSERT<\/code> \u2014 when a new row is added.<\/p>\n<\/li>\n<li data-start=\"306\" data-end=\"342\">\n<p data-start=\"308\" data-end=\"342\"><code class=\"\" data-line=\"\">UPDATE<\/code> \u2014 when a row is modified.<\/p>\n<\/li>\n<li data-start=\"343\" data-end=\"378\">\n<p data-start=\"345\" data-end=\"378\"><code class=\"\" data-line=\"\">DELETE<\/code> \u2014 when a row is removed.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"4331\" data-end=\"4371\">What are aggregate functions?<\/h3>\n<p data-start=\"0\" data-end=\"289\"><strong data-start=\"0\" data-end=\"23\">Aggregate functions<\/strong> are special functions in SQL (Structured Query Language) used to perform a <strong data-start=\"99\" data-end=\"133\">calculation on a set of values<\/strong> and return a <strong data-start=\"147\" data-end=\"176\">single summarizing result<\/strong>. They are commonly used with the <code class=\"\" data-line=\"\">GROUP BY<\/code> clause to group rows that have the same values in specified columns.<\/p>\n<p data-start=\"296\" data-end=\"336\"><strong>Common Aggregate Functions in SQL:<\/strong><\/p>\n<div class=\"_tableContainer_80l1q_1\">\n<div class=\"_tableWrapper_80l1q_14 group flex w-fit flex-col-reverse\" tabindex=\"-1\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"338\" data-end=\"681\">\n<thead data-start=\"338\" data-end=\"364\">\n<tr data-start=\"338\" data-end=\"364\">\n<th data-start=\"338\" data-end=\"349\" data-col-size=\"sm\">Function<\/th>\n<th data-start=\"349\" data-end=\"364\" data-col-size=\"md\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"392\" data-end=\"681\">\n<tr data-start=\"392\" data-end=\"452\">\n<td data-start=\"392\" data-end=\"404\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">COUNT()<\/code><\/td>\n<td data-start=\"404\" data-end=\"452\" data-col-size=\"md\">Counts the number of rows or non-NULL values<\/td>\n<\/tr>\n<tr data-start=\"453\" data-end=\"510\">\n<td data-start=\"453\" data-end=\"465\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">SUM()<\/code><\/td>\n<td data-start=\"465\" data-end=\"510\" data-col-size=\"md\">Returns the total sum of a numeric column<\/td>\n<\/tr>\n<tr data-start=\"511\" data-end=\"572\">\n<td data-start=\"511\" data-end=\"523\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">AVG()<\/code><\/td>\n<td data-start=\"523\" data-end=\"572\" data-col-size=\"md\">Returns the average value of a numeric column<\/td>\n<\/tr>\n<tr data-start=\"573\" data-end=\"627\">\n<td data-start=\"573\" data-end=\"585\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">MIN()<\/code><\/td>\n<td data-start=\"585\" data-end=\"627\" data-col-size=\"md\">Returns the smallest value in a column<\/td>\n<\/tr>\n<tr data-start=\"628\" data-end=\"681\">\n<td data-start=\"628\" data-end=\"640\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">MAX()<\/code><\/td>\n<td data-start=\"640\" data-end=\"681\" data-col-size=\"md\">Returns the largest value in a column<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3 data-start=\"4495\" data-end=\"4550\">What is the default order of sorting in SQL?<\/h3>\n<p data-start=\"0\" data-end=\"81\">In <strong data-start=\"3\" data-end=\"10\">SQL<\/strong>, the <strong data-start=\"16\" data-end=\"44\">default order of sorting<\/strong> when using the <code class=\"\" data-line=\"\">ORDER BY<\/code> clause is:<\/p>\n<p data-start=\"83\" data-end=\"116\"><strong>Ascending (ASC) order.<\/strong><\/p>\n<p data-start=\"118\" data-end=\"129\">This means:<\/p>\n<ul data-start=\"130\" data-end=\"312\">\n<li data-start=\"130\" data-end=\"196\">\n<p data-start=\"132\" data-end=\"196\">Numbers are sorted from <strong data-start=\"156\" data-end=\"179\">smallest to largest<\/strong> (e.g., 1, 2, 3\u2026)<\/p>\n<\/li>\n<li data-start=\"197\" data-end=\"265\">\n<p data-start=\"199\" data-end=\"265\">Text values (strings) are sorted in <strong data-start=\"235\" data-end=\"257\">alphabetical order<\/strong> (A \u2192 Z)<\/p>\n<\/li>\n<li data-start=\"266\" data-end=\"312\">\n<p data-start=\"268\" data-end=\"312\">Dates are sorted from <strong data-start=\"290\" data-end=\"312\">earliest to latest<\/strong><\/p>\n<\/li>\n<\/ul>\n<p data-start=\"532\" data-end=\"572\"><strong>If you want descending order:<\/strong><\/p>\n<p data-start=\"573\" data-end=\"595\">Use <code class=\"\" data-line=\"\">DESC<\/code> explicitly<\/p>\n<h3 data-start=\"4633\" data-end=\"4661\">What is GROUP BY?<\/h3>\n<p data-start=\"32\" data-end=\"287\">The <code class=\"\" data-line=\"\">GROUP BY<\/code> clause in SQL is used to group rows that have the same values in specified columns into summary rows, like <strong data-start=\"154\" data-end=\"184\">&#8220;total sales per customer&#8221;<\/strong> or <strong data-start=\"188\" data-end=\"228\">&#8220;number of students per department.&#8221;<\/strong> It is typically used with <strong data-start=\"255\" data-end=\"278\">aggregate functions<\/strong> such as:<\/p>\n<ul data-start=\"289\" data-end=\"439\">\n<li data-start=\"289\" data-end=\"317\">\n<p data-start=\"291\" data-end=\"317\"><code class=\"\" data-line=\"\">COUNT()<\/code> \u2013 to count items<\/p>\n<\/li>\n<li data-start=\"318\" data-end=\"343\">\n<p data-start=\"320\" data-end=\"343\"><code class=\"\" data-line=\"\">SUM()<\/code> \u2013 to add values<\/p>\n<\/li>\n<li data-start=\"344\" data-end=\"375\">\n<p data-start=\"346\" data-end=\"375\"><code class=\"\" data-line=\"\">AVG()<\/code> \u2013 to find the average<\/p>\n<\/li>\n<li data-start=\"376\" data-end=\"407\">\n<p data-start=\"378\" data-end=\"407\"><code class=\"\" data-line=\"\">MAX()<\/code> \u2013 to find the maximum<\/p>\n<\/li>\n<li data-start=\"408\" data-end=\"439\">\n<p data-start=\"410\" data-end=\"439\"><code class=\"\" data-line=\"\">MIN()<\/code> \u2013 to find the minimum<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"4929\" data-end=\"4982\">Difference between <code class=\"\" data-line=\"\">IS NULL<\/code> and <code class=\"\" data-line=\"\">= NULL<\/code>?<\/h3>\n<p data-start=\"0\" data-end=\"136\">The difference between <code class=\"\" data-line=\"\">IS NULL<\/code> and <code class=\"\" data-line=\"\">= NULL<\/code> in SQL is <strong data-start=\"56\" data-end=\"74\">very important<\/strong>, and misunderstanding it can lead to incorrect query results.<\/p>\n<p data-start=\"0\" data-end=\"136\">IS NULL<\/p>\n<ul data-start=\"160\" data-end=\"281\">\n<li data-start=\"160\" data-end=\"210\">\n<p data-start=\"162\" data-end=\"210\"><strong data-start=\"164\" data-end=\"179\">Correct way<\/strong> to check if a value is <code class=\"\" data-line=\"\">NULL<\/code>.<\/p>\n<\/li>\n<li data-start=\"211\" data-end=\"281\">\n<p data-start=\"213\" data-end=\"281\">Used to test whether a column or expression contains a <code class=\"\" data-line=\"\">NULL<\/code> value.<\/p>\n<\/li>\n<\/ul>\n<p>=NULL<\/p>\n<ul data-start=\"160\" data-end=\"281\">\n<li data-start=\"455\" data-end=\"491\">\n<p data-start=\"457\" data-end=\"491\"><strong data-start=\"459\" data-end=\"484\">Incorrect and invalid<\/strong> usage.<\/p>\n<\/li>\n<li data-start=\"492\" data-end=\"632\">\n<p data-start=\"494\" data-end=\"632\">In SQL, <code class=\"\" data-line=\"\">NULL<\/code> means &#8220;unknown&#8221;, and comparisons with <code class=\"\" data-line=\"\">NULL<\/code> using <code class=\"\" data-line=\"\">=<\/code> will always return <strong data-start=\"583\" data-end=\"592\">false<\/strong> or <strong data-start=\"596\" data-end=\"607\">unknown<\/strong>, not the desired result.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"5062\" data-end=\"5100\">What is a Stored Procedure?<\/h3>\n<p data-start=\"35\" data-end=\"310\">A <strong data-start=\"37\" data-end=\"57\">Stored Procedure<\/strong> is a precompiled collection of one or more SQL statements that are stored in the database and can be executed as a single unit. It allows you to encapsulate repetitive or complex SQL operations, making your code more reusable, organized, and efficient.<\/p>\n<p data-start=\"317\" data-end=\"358\"><strong>Key Features of Stored Procedures:<\/strong><\/p>\n<ul data-start=\"359\" data-end=\"736\">\n<li data-start=\"359\" data-end=\"421\">\n<p data-start=\"361\" data-end=\"421\"><strong data-start=\"361\" data-end=\"373\">Reusable<\/strong>: Once created, it can be called multiple times.<\/p>\n<\/li>\n<li data-start=\"422\" data-end=\"497\">\n<p data-start=\"424\" data-end=\"497\"><strong data-start=\"424\" data-end=\"439\">Precompiled<\/strong>: Executed faster as it is compiled and stored in advance.<\/p>\n<\/li>\n<li data-start=\"498\" data-end=\"577\">\n<p data-start=\"500\" data-end=\"577\"><strong data-start=\"500\" data-end=\"521\">Parameter Support<\/strong>: Can accept input, output, or both types of parameters.<\/p>\n<\/li>\n<li data-start=\"578\" data-end=\"653\">\n<p data-start=\"580\" data-end=\"653\"><strong data-start=\"580\" data-end=\"601\">Improves Security<\/strong>: Reduces SQL injection by avoiding dynamic queries.<\/p>\n<\/li>\n<li data-start=\"654\" data-end=\"736\">\n<p data-start=\"656\" data-end=\"736\"><strong data-start=\"656\" data-end=\"673\">Encapsulation<\/strong>: Hides the implementation details and promotes modular design.<\/p>\n<\/li>\n<\/ul>\n<h3><strong>What are wildcards?<\/strong><\/h3>\n<p data-start=\"0\" data-end=\"263\"><strong data-start=\"0\" data-end=\"13\">Wildcards<\/strong> are special symbols used in search operations or pattern matching to represent one or more characters. They allow users to perform flexible and dynamic searches, especially when the exact term is not known or when searching for variations of a term.<\/p>\n<p data-start=\"270\" data-end=\"294\"><strong>Common Wildcards:<\/strong><\/p>\n<h4 data-start=\"296\" data-end=\"320\">1. <strong data-start=\"304\" data-end=\"320\">Asterisk (*)<\/strong><\/h4>\n<ul data-start=\"321\" data-end=\"433\">\n<li data-start=\"321\" data-end=\"363\">\n<p data-start=\"323\" data-end=\"363\"><strong data-start=\"323\" data-end=\"338\">Represents:<\/strong> Zero or more characters.<\/p>\n<\/li>\n<li data-start=\"364\" data-end=\"433\">\n<p data-start=\"366\" data-end=\"380\"><strong data-start=\"366\" data-end=\"378\">Example:<\/strong><\/p>\n<ul data-start=\"383\" data-end=\"433\">\n<li data-start=\"383\" data-end=\"433\">\n<p data-start=\"385\" data-end=\"433\"><code class=\"\" data-line=\"\">doc*<\/code> matches <code class=\"\" data-line=\"\">doc<\/code>, <code class=\"\" data-line=\"\">document<\/code>, <code class=\"\" data-line=\"\">doctor<\/code>, etc.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4 data-start=\"435\" data-end=\"464\">2. <strong data-start=\"443\" data-end=\"464\">Question Mark (?)<\/strong><\/h4>\n<ul data-start=\"465\" data-end=\"579\">\n<li data-start=\"465\" data-end=\"502\">\n<p data-start=\"467\" data-end=\"502\"><strong data-start=\"467\" data-end=\"482\">Represents:<\/strong> A single character.<\/p>\n<\/li>\n<li data-start=\"503\" data-end=\"579\">\n<p data-start=\"505\" data-end=\"519\"><strong data-start=\"505\" data-end=\"517\">Example:<\/strong><\/p>\n<ul data-start=\"522\" data-end=\"579\">\n<li data-start=\"522\" data-end=\"579\">\n<p data-start=\"524\" data-end=\"579\"><code class=\"\" data-line=\"\">te?t<\/code> matches <code class=\"\" data-line=\"\">text<\/code>, <code class=\"\" data-line=\"\">test<\/code>, <code class=\"\" data-line=\"\">tent<\/code>, but not <code class=\"\" data-line=\"\">teest<\/code>.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4 data-start=\"581\" data-end=\"623\">3. <strong data-start=\"589\" data-end=\"623\">Character Sets (used in RegEx)<\/strong><\/h4>\n<ul data-start=\"624\" data-end=\"735\">\n<li data-start=\"624\" data-end=\"681\">\n<p data-start=\"626\" data-end=\"681\"><strong data-start=\"626\" data-end=\"635\">[abc]<\/strong> matches any one of the characters a, b, or c.<\/p>\n<\/li>\n<li data-start=\"682\" data-end=\"735\">\n<p data-start=\"684\" data-end=\"735\"><strong data-start=\"684\" data-end=\"693\">[a-z]<\/strong> matches any lowercase letter from a to z.<\/p>\n<\/li>\n<\/ul>\n<h4 data-start=\"737\" data-end=\"773\">4. <strong data-start=\"745\" data-end=\"773\">Negation (used in RegEx)<\/strong><\/h4>\n<ul data-start=\"774\" data-end=\"827\">\n<li data-start=\"774\" data-end=\"827\">\n<p data-start=\"776\" data-end=\"827\"><strong data-start=\"776\" data-end=\"786\">[^abc]<\/strong> matches any character except a, b, or c.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"5380\" data-end=\"5413\">What is a transaction?<\/h3>\n<p data-start=\"28\" data-end=\"239\">A <strong data-start=\"30\" data-end=\"45\">transaction<\/strong> in the context of databases (especially relational databases like MySQL, SQL Server, Oracle, etc.) is a <strong data-start=\"150\" data-end=\"192\">sequence of one or more SQL operations<\/strong> executed as a <strong data-start=\"207\" data-end=\"238\">single logical unit of work<\/strong>.<\/p>\n<p data-start=\"241\" data-end=\"436\">A transaction ensures that either <strong data-start=\"275\" data-end=\"293\">all operations<\/strong> within it are <strong data-start=\"308\" data-end=\"345\">executed successfully (committed)<\/strong> or <strong data-start=\"349\" data-end=\"383\">none are applied (rolled back)<\/strong>, maintaining <strong data-start=\"397\" data-end=\"415\">data integrity<\/strong> and <strong data-start=\"420\" data-end=\"435\">consistency<\/strong>.<\/p>\n<h3 data-start=\"5557\" data-end=\"5593\">What are ACID properties?<\/h3>\n<p data-start=\"181\" data-end=\"201\"><strong data-start=\"188\" data-end=\"201\">Atomicity<\/strong><\/p>\n<ul data-start=\"202\" data-end=\"530\">\n<li data-start=\"202\" data-end=\"373\">\n<p data-start=\"204\" data-end=\"373\"><strong data-start=\"204\" data-end=\"219\">Definition:<\/strong> A transaction must be treated as a single, indivisible unit. Either <strong data-start=\"288\" data-end=\"306\">all operations<\/strong> within the transaction are executed successfully, or <strong data-start=\"360\" data-end=\"372\">none are<\/strong>.<\/p>\n<\/li>\n<li data-start=\"374\" data-end=\"530\">\n<p data-start=\"376\" data-end=\"530\"><strong data-start=\"376\" data-end=\"388\">Example:<\/strong> If a bank transfer involves debiting one account and crediting another, both operations must succeed; if one fails, both must be rolled back.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"537\" data-end=\"559\"><strong data-start=\"544\" data-end=\"559\">Consistency<\/strong><\/p>\n<ul data-start=\"560\" data-end=\"833\">\n<li data-start=\"560\" data-end=\"694\">\n<p data-start=\"562\" data-end=\"694\"><strong data-start=\"562\" data-end=\"577\">Definition:<\/strong> A transaction must take the database from one <strong data-start=\"624\" data-end=\"650\">valid state to another<\/strong>, maintaining the integrity of the database.<\/p>\n<\/li>\n<li data-start=\"695\" data-end=\"833\">\n<p data-start=\"697\" data-end=\"833\"><strong data-start=\"697\" data-end=\"709\">Example:<\/strong> If there&#8217;s a rule that an account balance can&#8217;t go below zero, a transaction that violates this rule will not be committed.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"840\" data-end=\"860\"><strong data-start=\"847\" data-end=\"860\">Isolation<\/strong><\/p>\n<ul data-start=\"861\" data-end=\"1140\">\n<li data-start=\"861\" data-end=\"1008\">\n<p data-start=\"863\" data-end=\"1008\"><strong data-start=\"863\" data-end=\"878\">Definition:<\/strong> Transactions must execute independently of one another. <strong data-start=\"935\" data-end=\"958\">Intermediate states<\/strong> of a transaction should not be visible to others.<\/p>\n<\/li>\n<li data-start=\"1009\" data-end=\"1140\">\n<p data-start=\"1011\" data-end=\"1140\"><strong data-start=\"1011\" data-end=\"1023\">Example:<\/strong> If two users transfer money at the same time, each transaction should execute as if it&#8217;s the <strong data-start=\"1117\" data-end=\"1129\">only one<\/strong> happening.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"1147\" data-end=\"1168\"><strong data-start=\"1154\" data-end=\"1168\">Durability<\/strong><\/p>\n<ul data-start=\"1169\" data-end=\"1402\">\n<li data-start=\"1169\" data-end=\"1286\">\n<p data-start=\"1171\" data-end=\"1286\"><strong data-start=\"1171\" data-end=\"1186\">Definition:<\/strong> Once a transaction is committed, its changes are <strong data-start=\"1236\" data-end=\"1249\">permanent<\/strong>, even in the case of system crashes.<\/p>\n<\/li>\n<li data-start=\"1287\" data-end=\"1402\">\n<p data-start=\"1289\" data-end=\"1402\"><strong data-start=\"1289\" data-end=\"1301\">Example:<\/strong> After transferring money and getting a success message, even a power outage won\u2019t undo the transfer.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"5679\" data-end=\"5712\">What is the IN clause?<\/h3>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary select-none rounded-t-2xl\">\n<p data-start=\"40\" data-end=\"245\">The <code class=\"\" data-line=\"\">IN<\/code> clause in SQL is <strong data-start=\"66\" data-end=\"99\">used to filter the result set<\/strong> by checking if a column&#8217;s value <strong data-start=\"132\" data-end=\"153\">matches any value<\/strong> in a specified list. It simplifies multiple <code class=\"\" data-line=\"\">OR<\/code> conditions and improves query readability.<\/p>\n<p data-start=\"40\" data-end=\"245\">Syntax:<\/p>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">SELECT column1, column2<br\/>FROM table_name<br\/>WHERE column_name IN (value1, value2, value3, ...);<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<\/div>\n<\/div>\n<h3 data-start=\"5776\" data-end=\"5838\">What is the difference between UNION and UNION ALL?<\/h3>\n<p>The <strong data-start=\"4\" data-end=\"50\">difference between <code class=\"\" data-line=\"\">UNION<\/code> and <code class=\"\" data-line=\"\">UNION ALL<\/code><\/strong> in SQL lies in how they handle <strong data-start=\"82\" data-end=\"100\">duplicate rows<\/strong> when combining the results of two or more <code class=\"\" data-line=\"\">SELECT<\/code> queries:<\/p>\n<p data-start=\"167\" data-end=\"181\"><strong>Union<\/strong><\/p>\n<ul data-start=\"182\" data-end=\"370\">\n<li data-start=\"182\" data-end=\"231\">\n<p data-start=\"184\" data-end=\"231\"><strong data-start=\"184\" data-end=\"210\">Removes duplicate rows<\/strong> from the result set.<\/p>\n<\/li>\n<li data-start=\"232\" data-end=\"302\">\n<p data-start=\"234\" data-end=\"302\">Performs an <strong data-start=\"246\" data-end=\"267\">implicit DISTINCT<\/strong>, so only unique rows are returned.<\/p>\n<\/li>\n<li data-start=\"303\" data-end=\"370\">\n<p data-start=\"305\" data-end=\"370\">Slightly <strong data-start=\"314\" data-end=\"324\">slower<\/strong> due to the extra step of removing duplicates.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"535\" data-end=\"553\"><strong>Union All<\/strong><\/p>\n<ul data-start=\"554\" data-end=\"699\">\n<li data-start=\"554\" data-end=\"601\">\n<p data-start=\"556\" data-end=\"601\"><strong data-start=\"556\" data-end=\"574\">Keeps all rows<\/strong>, including <strong data-start=\"586\" data-end=\"600\">duplicates<\/strong>.<\/p>\n<\/li>\n<li data-start=\"602\" data-end=\"640\">\n<p data-start=\"604\" data-end=\"640\">Does <strong data-start=\"609\" data-end=\"623\">not remove<\/strong> repeated values.<\/p>\n<\/li>\n<li data-start=\"641\" data-end=\"699\">\n<p data-start=\"643\" data-end=\"699\"><strong data-start=\"643\" data-end=\"653\">Faster<\/strong> because it skips the duplicate-checking step.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"5916\" data-end=\"5953\">What is a temporary table?<\/h3>\n<p data-start=\"0\" data-end=\"239\">A <strong data-start=\"2\" data-end=\"21\">temporary table<\/strong> is a special type of table in a database that is created and used temporarily during a session or transaction. It stores intermediate results or temporary data that doesn&#8217;t need to be kept permanently in the database.<\/p>\n<p data-start=\"241\" data-end=\"281\"><strong>Key Features of Temporary Tables:<\/strong><\/p>\n<ol data-start=\"283\" data-end=\"724\">\n<li data-start=\"283\" data-end=\"376\">\n<p data-start=\"286\" data-end=\"376\"><strong data-start=\"286\" data-end=\"301\">Short-lived<\/strong>: Exists only for the duration of a session or until it\u2019s manually dropped.<\/p>\n<\/li>\n<li data-start=\"377\" data-end=\"457\">\n<p data-start=\"380\" data-end=\"457\"><strong data-start=\"380\" data-end=\"400\">Session-specific<\/strong>: Usually only accessible to the session that created it.<\/p>\n<\/li>\n<li data-start=\"458\" data-end=\"558\">\n<p data-start=\"461\" data-end=\"558\"><strong data-start=\"461\" data-end=\"481\">Stored in TempDB<\/strong> (in SQL Server): The data is physically stored in a special system database.<\/p>\n<\/li>\n<li data-start=\"559\" data-end=\"724\">\n<p data-start=\"562\" data-end=\"576\"><strong data-start=\"562\" data-end=\"575\">Use Cases<\/strong>:<\/p>\n<ul data-start=\"580\" data-end=\"724\">\n<li data-start=\"580\" data-end=\"633\">\n<p data-start=\"582\" data-end=\"633\">Storing intermediate results during complex queries<\/p>\n<\/li>\n<li data-start=\"637\" data-end=\"676\">\n<p data-start=\"639\" data-end=\"676\">Simplifying joins and data processing<\/p>\n<\/li>\n<li data-start=\"680\" data-end=\"724\">\n<p data-start=\"682\" data-end=\"724\">Improving performance for batch processing<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p data-start=\"6079\" data-end=\"6123\"><strong>Types of Temporary Tables in SQL:<\/strong><\/p>\n<ul>\n<li data-start=\"777\" data-end=\"802\">Local Temporary Table<\/li>\n<li data-start=\"777\" data-end=\"802\">Global Temporary Table<\/li>\n<\/ul>\n<h3 data-start=\"6079\" data-end=\"6123\">Difference between EXISTS and IN?<\/h3>\n<p>The <strong data-start=\"4\" data-end=\"44\">difference between <code class=\"\" data-line=\"\">EXISTS<\/code> and <code class=\"\" data-line=\"\">IN<\/code><\/strong> in SQL lies in how they work internally and their performance characteristics. Both are used to <strong data-start=\"141\" data-end=\"176\">filter data based on subqueries<\/strong>, but they behave differently.<\/p>\n<table>\n<thead>\n<tr>\n<th>Feature<\/th>\n<th><code class=\"\" data-line=\"\">IN<\/code><\/th>\n<th><code class=\"\" data-line=\"\">EXISTS<\/code><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Compares<\/td>\n<td>Values returned by subquery<\/td>\n<td>Existence of rows<\/td>\n<\/tr>\n<tr>\n<td>Evaluation<\/td>\n<td>Fetches all values and compares<\/td>\n<td>Stops at first match (faster in some cases)<\/td>\n<\/tr>\n<tr>\n<td>Null Handling<\/td>\n<td>Can behave unexpectedly with NULLs<\/td>\n<td>Ignores NULLs and returns correctly<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li data-start=\"2628\" data-end=\"2705\">\n<p data-start=\"2630\" data-end=\"2705\">Use <strong data-start=\"2634\" data-end=\"2642\"><code class=\"\" data-line=\"\">IN<\/code><\/strong> for comparing values directly from a list or a small subquery.<\/p>\n<\/li>\n<li data-start=\"2706\" data-end=\"2846\">\n<p data-start=\"2708\" data-end=\"2846\">Use <strong data-start=\"2712\" data-end=\"2724\"><code class=\"\" data-line=\"\">EXISTS<\/code><\/strong> when you&#8217;re testing for <strong data-start=\"2749\" data-end=\"2766\">row existence<\/strong> and especially when dealing with <strong data-start=\"2800\" data-end=\"2825\">correlated subqueries<\/strong> or <strong data-start=\"2829\" data-end=\"2845\">large tables<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"6258\" data-end=\"6285\">How to use CASE?<\/h3>\n<p data-start=\"0\" data-end=\"131\">In <strong data-start=\"3\" data-end=\"10\">SQL<\/strong>, the <code class=\"\" data-line=\"\">CASE<\/code> statement is used to apply <strong data-start=\"50\" data-end=\"71\">conditional logic<\/strong> within queries \u2014 similar to <code class=\"\" data-line=\"\">if-else<\/code> logic in programming.<\/p>\n<p data-start=\"0\" data-end=\"131\">Basic Syntax of CASE (Simple CASE)<\/p>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SELECT column1,<br\/>       CASE column2<br\/>           WHEN &#039;value1&#039; THEN &#039;Result1&#039;<br\/>           WHEN &#039;value2&#039; THEN &#039;Result2&#039;<br\/>           ELSE &#039;DefaultResult&#039;<br\/>       END AS alias_name<br\/>FROM table_name;<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\"><\/div>\n<h3 data-start=\"6417\" data-end=\"6458\">What is a correlated subquery?<\/h3>\n<p data-start=\"38\" data-end=\"197\">A <strong data-start=\"40\" data-end=\"63\">correlated subquery<\/strong> is a subquery that <strong data-start=\"83\" data-end=\"128\">depends on the outer query for its values<\/strong>. It is evaluated <strong data-start=\"146\" data-end=\"167\">once for each row<\/strong> processed by the outer query.<\/p>\n<p data-start=\"204\" data-end=\"231\"><strong>Key Characteristics:<\/strong><\/p>\n<ul data-start=\"232\" data-end=\"407\">\n<li data-start=\"232\" data-end=\"281\">\n<p data-start=\"234\" data-end=\"281\">It <strong data-start=\"237\" data-end=\"280\">references columns from the outer query<\/strong>.<\/p>\n<\/li>\n<li data-start=\"282\" data-end=\"352\">\n<p data-start=\"284\" data-end=\"352\">It is <strong data-start=\"290\" data-end=\"313\">executed repeatedly<\/strong>, once for each row in the outer query.<\/p>\n<\/li>\n<li data-start=\"353\" data-end=\"407\">\n<p data-start=\"355\" data-end=\"407\">Cannot be executed independently of the outer query.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"6522\" data-end=\"6550\">What is an alias?<\/h3>\n<p data-start=\"0\" data-end=\"144\">In <strong data-start=\"3\" data-end=\"10\">SQL<\/strong>, an <strong data-start=\"15\" data-end=\"24\">alias<\/strong> is a temporary name that you assign to a <strong data-start=\"66\" data-end=\"75\">table<\/strong> or a <strong data-start=\"81\" data-end=\"91\">column<\/strong> to make your queries easier to read or more concise.<\/p>\n<ul data-start=\"933\" data-end=\"1214\">\n<li data-start=\"933\" data-end=\"1006\">\n<p data-start=\"935\" data-end=\"1006\"><strong data-start=\"935\" data-end=\"960\">Aliases are temporary<\/strong> and only exist for the duration of the query.<\/p>\n<\/li>\n<li data-start=\"1007\" data-end=\"1140\">\n<p data-start=\"1009\" data-end=\"1140\">The <strong data-start=\"1013\" data-end=\"1041\"><code class=\"\" data-line=\"\">AS<\/code> keyword is optional<\/strong>; you can write <code class=\"\" data-line=\"\">SELECT first_name Name<\/code> instead of <code class=\"\" data-line=\"\">AS Name<\/code>, but using <code class=\"\" data-line=\"\">AS<\/code> improves readability.<\/p>\n<\/li>\n<li data-start=\"1141\" data-end=\"1214\">\n<p data-start=\"1143\" data-end=\"1214\">Useful in <strong data-start=\"1153\" data-end=\"1172\">complex queries<\/strong> for better understanding and maintenance.<\/p>\n<\/li>\n<\/ul>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary select-none rounded-t-2xl\">\n<p data-start=\"151\" data-end=\"170\"><strong>Column Alias<\/strong><\/p>\n<ul>\n<li data-start=\"171\" data-end=\"217\">Used to rename a <strong data-start=\"188\" data-end=\"198\">column<\/strong> in the result set.<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<p data-start=\"505\" data-end=\"523\"><strong>Table Alias<\/strong><\/p>\n<ul>\n<li data-start=\"524\" data-end=\"617\">Used to give a <strong data-start=\"539\" data-end=\"557\">temporary name<\/strong> to a table, often used in <strong data-start=\"584\" data-end=\"593\">JOINs<\/strong> to simplify references.<\/li>\n<\/ul>\n<h3 data-start=\"6658\" data-end=\"6686\">What is DISTINCT?<\/h3>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\">The <code class=\"\" data-line=\"\">DISTINCT<\/code> keyword in SQL is used to <strong data-start=\"73\" data-end=\"100\">remove duplicate values<\/strong> from the result set of a query. It ensures that the output contains <strong data-start=\"169\" data-end=\"199\">only unique (non-repeated)<\/strong> rows for the specified column(s).<\/div>\n<div dir=\"ltr\">\n<ul data-start=\"1031\" data-end=\"1172\">\n<li data-start=\"1031\" data-end=\"1080\">\n<p data-start=\"1033\" data-end=\"1080\">Removing duplicate entries from search results.<\/p>\n<\/li>\n<li data-start=\"1081\" data-end=\"1124\">\n<p data-start=\"1083\" data-end=\"1124\">Summarizing unique categories or regions.<\/p>\n<\/li>\n<li data-start=\"1125\" data-end=\"1172\">\n<p data-start=\"1127\" data-end=\"1172\">Cleaning data before processing or reporting.<\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<h3 data-start=\"6766\" data-end=\"6794\">What is a schema?<\/h3>\n<p data-start=\"176\" data-end=\"374\">A <strong data-start=\"178\" data-end=\"188\">schema<\/strong> is like a <strong data-start=\"199\" data-end=\"206\">map<\/strong> or <strong data-start=\"210\" data-end=\"220\">layout<\/strong> for a database. It tells the database what kind of data can be stored, how the data is structured, and how different pieces of data relate to each other.<\/p>\n<p data-start=\"381\" data-end=\"415\"><strong>Key Components of a Schema:<\/strong><\/p>\n<p data-start=\"416\" data-end=\"453\">A database schema typically includes:<\/p>\n<ul data-start=\"454\" data-end=\"800\">\n<li data-start=\"454\" data-end=\"492\">\n<p data-start=\"456\" data-end=\"492\"><strong data-start=\"456\" data-end=\"466\">Tables<\/strong> (e.g., <code class=\"\" data-line=\"\">Users<\/code>, <code class=\"\" data-line=\"\">Orders<\/code>)<\/p>\n<\/li>\n<li data-start=\"493\" data-end=\"544\">\n<p data-start=\"495\" data-end=\"544\"><strong data-start=\"495\" data-end=\"506\">Columns<\/strong> (e.g., <code class=\"\" data-line=\"\">name<\/code>, <code class=\"\" data-line=\"\">email<\/code>, <code class=\"\" data-line=\"\">order_date<\/code>)<\/p>\n<\/li>\n<li data-start=\"545\" data-end=\"594\">\n<p data-start=\"547\" data-end=\"594\"><strong data-start=\"547\" data-end=\"561\">Data Types<\/strong> (e.g., <code class=\"\" data-line=\"\">VARCHAR<\/code>, <code class=\"\" data-line=\"\">INT<\/code>, <code class=\"\" data-line=\"\">DATE<\/code>)<\/p>\n<\/li>\n<li data-start=\"595\" data-end=\"699\">\n<p data-start=\"597\" data-end=\"606\"><strong data-start=\"597\" data-end=\"605\">Keys<\/strong>:<\/p>\n<ul data-start=\"609\" data-end=\"699\">\n<li data-start=\"609\" data-end=\"654\">\n<p data-start=\"611\" data-end=\"654\"><strong data-start=\"611\" data-end=\"626\">Primary Key<\/strong> (uniquely identifies a row)<\/p>\n<\/li>\n<li data-start=\"657\" data-end=\"699\">\n<p data-start=\"659\" data-end=\"699\"><strong data-start=\"659\" data-end=\"674\">Foreign Key<\/strong> (links to another table)<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li data-start=\"700\" data-end=\"746\">\n<p data-start=\"702\" data-end=\"746\"><strong data-start=\"702\" data-end=\"717\">Constraints<\/strong> (e.g., <code class=\"\" data-line=\"\">NOT NULL<\/code>, <code class=\"\" data-line=\"\">UNIQUE<\/code>)<\/p>\n<\/li>\n<li data-start=\"747\" data-end=\"800\">\n<p data-start=\"749\" data-end=\"800\"><strong data-start=\"749\" data-end=\"766\">Relationships<\/strong> (e.g., one-to-many, many-to-many)<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"807\" data-end=\"832\"><strong>Types of Schemas:<\/strong><\/p>\n<ol data-start=\"833\" data-end=\"1026\">\n<li data-start=\"833\" data-end=\"903\">\n<p data-start=\"836\" data-end=\"903\"><strong data-start=\"836\" data-end=\"855\">Physical Schema<\/strong>: Defines how data is stored physically on disk.<\/p>\n<\/li>\n<li data-start=\"904\" data-end=\"1026\">\n<p data-start=\"907\" data-end=\"1026\"><strong data-start=\"907\" data-end=\"925\">Logical Schema<\/strong>: Describes tables, columns, data types, and relationships\u2014more relevant to developers and designers.<\/p>\n<\/li>\n<\/ol>\n<h3 data-start=\"6884\" data-end=\"6919\">What is a recursive CTE?<\/h3>\n<p data-start=\"0\" data-end=\"295\">A <strong data-start=\"2\" data-end=\"19\">recursive CTE<\/strong> (Common Table Expression) is a special type of CTE in SQL that <strong data-start=\"83\" data-end=\"104\">references itself<\/strong> in order to perform <strong data-start=\"125\" data-end=\"150\">repetitive operations<\/strong>, typically used to <strong data-start=\"170\" data-end=\"216\">query hierarchical or tree-structured data<\/strong>, such as organizational charts, file systems, or bill-of-materials structures.<\/p>\n<p data-start=\"338\" data-end=\"376\">A <strong data-start=\"340\" data-end=\"357\">recursive CTE<\/strong> has <strong data-start=\"362\" data-end=\"375\">two parts<\/strong>:<\/p>\n<ol data-start=\"377\" data-end=\"560\">\n<li data-start=\"377\" data-end=\"464\">\n<p data-start=\"380\" data-end=\"464\"><strong data-start=\"380\" data-end=\"397\">Anchor member<\/strong>: The base result set. This is the starting point of the recursion.<\/p>\n<\/li>\n<li data-start=\"465\" data-end=\"560\">\n<p data-start=\"468\" data-end=\"560\"><strong data-start=\"468\" data-end=\"488\">Recursive member<\/strong>: A query that refers to the CTE itself and builds on the anchor member.<\/p>\n<\/li>\n<\/ol>\n<h3 data-start=\"6971\" data-end=\"7006\">What is a composite key?<\/h3>\n<p data-start=\"0\" data-end=\"149\">A <strong data-start=\"2\" data-end=\"19\">composite key<\/strong> is a combination of <strong data-start=\"40\" data-end=\"63\">two or more columns<\/strong> in a database table that together <strong data-start=\"98\" data-end=\"128\">uniquely identify a record<\/strong> (row) in that table.<\/p>\n<p><strong>Key Points:<\/strong><\/p>\n<ul data-start=\"170\" data-end=\"382\">\n<li data-start=\"170\" data-end=\"247\">\n<p data-start=\"172\" data-end=\"247\"><strong data-start=\"172\" data-end=\"202\">Used when no single column<\/strong> is sufficient to uniquely identify a record.<\/p>\n<\/li>\n<li data-start=\"248\" data-end=\"316\">\n<p data-start=\"250\" data-end=\"316\">All parts of the composite key are required to enforce uniqueness.<\/p>\n<\/li>\n<li data-start=\"317\" data-end=\"382\">\n<p data-start=\"319\" data-end=\"382\">Often used in <strong data-start=\"333\" data-end=\"352\">junction tables<\/strong> (many-to-many relationships).<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"7060\" data-end=\"7096\">What is the use of LIMIT?<\/h3>\n<p data-start=\"0\" data-end=\"150\">The <code class=\"\" data-line=\"\">LIMIT<\/code> clause is used in <strong data-start=\"30\" data-end=\"65\">SQL (Structured Query Language)<\/strong> to <strong data-start=\"69\" data-end=\"100\">restrict the number of rows<\/strong> returned by a query. It\u2019s especially useful when:<\/p>\n<ul data-start=\"152\" data-end=\"367\">\n<li data-start=\"152\" data-end=\"211\">\n<p data-start=\"154\" data-end=\"211\">You want to preview just a few rows from a large dataset.<\/p>\n<\/li>\n<li data-start=\"212\" data-end=\"285\">\n<p data-start=\"214\" data-end=\"285\">You&#8217;re implementing <strong data-start=\"234\" data-end=\"248\">pagination<\/strong> (e.g., showing 10 results per page).<\/p>\n<\/li>\n<li data-start=\"286\" data-end=\"367\">\n<p data-start=\"288\" data-end=\"367\">You only need the <strong data-start=\"306\" data-end=\"323\">top N records<\/strong> (like highest scores, recent orders, etc.).<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"7183\" data-end=\"7217\">What are SET operators?<\/h3>\n<ul data-start=\"7218\" data-end=\"7274\">\n<li data-start=\"7218\" data-end=\"7229\">\n<p data-start=\"7220\" data-end=\"7229\">Union<\/p>\n<\/li>\n<li data-start=\"7230\" data-end=\"7245\">\n<p data-start=\"7232\" data-end=\"7245\">Union All<\/p>\n<\/li>\n<li data-start=\"7246\" data-end=\"7261\">\n<p data-start=\"7248\" data-end=\"7261\">Intersect<\/p>\n<\/li>\n<li data-start=\"7262\" data-end=\"7274\">\n<p data-start=\"7264\" data-end=\"7274\">Except<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"7281\" data-end=\"7311\">What is COALESCE()?<\/h3>\n<p data-start=\"7312\" data-end=\"7355\">The <code class=\"\" data-line=\"\">COALESCE()<\/code> function in SQL is used to return the <strong data-start=\"55\" data-end=\"79\">first non-null value<\/strong> from a list of expressions.<\/p>\n<p data-start=\"202\" data-end=\"226\"><strong data-start=\"209\" data-end=\"226\">How It Works:<\/strong><\/p>\n<ul data-start=\"228\" data-end=\"406\">\n<li data-start=\"228\" data-end=\"301\">\n<p data-start=\"230\" data-end=\"301\"><code class=\"\" data-line=\"\">COALESCE()<\/code> checks each expression in the list <strong data-start=\"278\" data-end=\"300\">from left to right<\/strong>.<\/p>\n<\/li>\n<li data-start=\"302\" data-end=\"352\">\n<p data-start=\"304\" data-end=\"352\">It returns the <strong data-start=\"319\" data-end=\"351\">first value that is not NULL<\/strong>.<\/p>\n<\/li>\n<li data-start=\"353\" data-end=\"406\">\n<p data-start=\"355\" data-end=\"406\">If <strong data-start=\"358\" data-end=\"386\">all expressions are NULL<\/strong>, it returns <code class=\"\" data-line=\"\">NULL<\/code>.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"7362\" data-end=\"7406\">How do you prevent SQL injection?<\/h3>\n<p data-start=\"174\" data-end=\"235\"><strong data-start=\"184\" data-end=\"235\">Use Prepared Statements (Parameterized Queries)<\/strong><\/p>\n<ul>\n<li data-start=\"236\" data-end=\"312\">This is the <strong data-start=\"248\" data-end=\"282\">most effective and recommended<\/strong> way to prevent SQL injection.<\/li>\n<li data-start=\"236\" data-end=\"312\">Prepared statements separate SQL logic from data, so even if user input contains SQL code, it will be treated as plain text.<\/li>\n<\/ul>\n<p data-start=\"735\" data-end=\"788\"><strong data-start=\"745\" data-end=\"788\">Use Stored Procedures (with parameters)<\/strong><\/p>\n<p data-start=\"789\" data-end=\"861\">Stored procedures can also prevent injection when implemented correctly.<\/p>\n<p data-start=\"1070\" data-end=\"1101\"><strong data-start=\"1080\" data-end=\"1101\">Avoid Dynamic SQL<\/strong><\/p>\n<p data-start=\"1102\" data-end=\"1174\">Don\u2019t build SQL queries by concatenating strings or user input directly.<\/p>\n<p data-start=\"1354\" data-end=\"1397\"><strong data-start=\"1364\" data-end=\"1397\">Input Validation and Escaping<\/strong><\/p>\n<ul data-start=\"1398\" data-end=\"1629\">\n<li data-start=\"1398\" data-end=\"1454\">\n<p data-start=\"1400\" data-end=\"1454\">Allow only expected characters using <strong data-start=\"1437\" data-end=\"1453\">whitelisting<\/strong>.<\/p>\n<\/li>\n<li data-start=\"1455\" data-end=\"1547\">\n<p data-start=\"1457\" data-end=\"1547\">Use built-in validation libraries to ensure correct formats (e.g., emails, phone numbers).<\/p>\n<\/li>\n<li data-start=\"1548\" data-end=\"1629\">\n<p data-start=\"1550\" data-end=\"1629\">Escaping input is a last resort and not foolproof\u2014prefer parameterized queries.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"7477\" data-end=\"7505\">What is NULLIF()?<\/h3>\n<p data-start=\"32\" data-end=\"190\">The <code class=\"\" data-line=\"\">NULLIF()<\/code> function in SQL is used to <strong data-start=\"74\" data-end=\"101\">compare two expressions<\/strong> and <strong data-start=\"106\" data-end=\"141\">return <code class=\"\" data-line=\"\">NULL<\/code> if they are equal<\/strong>. Otherwise, it returns the <strong data-start=\"169\" data-end=\"189\">first expression<\/strong>.<\/p>\n<p data-start=\"32\" data-end=\"190\">Syntax:<\/p>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">NULLIF(expression1, expression2)<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<p data-start=\"32\" data-end=\"190\"><code class=\"\" data-line=\"\">NULLIF()<\/code> is often used in <strong data-start=\"890\" data-end=\"913\">data transformation<\/strong>, <strong data-start=\"915\" data-end=\"927\">cleaning<\/strong>, and <strong data-start=\"933\" data-end=\"951\">error handling<\/strong> scenarios, especially where conditional nulls are useful.<\/p>\n<h3 data-start=\"7554\" data-end=\"7596\">What are common SQL data types?<\/h3>\n<ul>\n<li><strong>Numeric Data Types<\/strong><\/li>\n<li><strong>Character\/String Data Types<\/strong><\/li>\n<li><strong>Date and Time Data Types<\/strong><\/li>\n<li><strong>Boolean Data Type<\/strong><\/li>\n<\/ul>\n<h3 data-start=\"7668\" data-end=\"7711\">How do you update multiple rows?<\/h3>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between h-9 bg-token-sidebar-surface-primary select-none rounded-t-2xl\">To <strong data-start=\"3\" data-end=\"27\">update multiple rows<\/strong> in a SQL table, you use the <code class=\"\" data-line=\"\">UPDATE<\/code> statement with a <code class=\"\" data-line=\"\">WHERE<\/code> clause that targets multiple rows.<\/div>\n<div><strong>Syntax:<\/strong><\/div>\n<div>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">UPDATE table_name<br\/>SET column1 = value1,<br\/>    column2 = value2,<br\/>    ...<br\/>WHERE condition;<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<\/div>\n<\/div>\n<h3 data-start=\"7793\" data-end=\"7859\">What is the difference between RANK() and ROW_NUMBER()?<\/h3>\n<h3 data-start=\"137\" data-end=\"158\"><code class=\"\" data-line=\"\">ROW_NUMBER()<\/code><\/h3>\n<ul data-start=\"160\" data-end=\"313\">\n<li data-start=\"160\" data-end=\"213\">\n<p data-start=\"162\" data-end=\"213\">Assigns a <strong data-start=\"172\" data-end=\"182\">unique<\/strong> sequential number to each row.<\/p>\n<\/li>\n<li data-start=\"214\" data-end=\"241\">\n<p data-start=\"216\" data-end=\"241\"><strong data-start=\"216\" data-end=\"227\">No gaps<\/strong> in numbering.<\/p>\n<\/li>\n<li data-start=\"242\" data-end=\"313\">\n<p data-start=\"244\" data-end=\"313\">Even if rows have the same value, they get <strong data-start=\"287\" data-end=\"312\">different row numbers<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"714\" data-end=\"729\"><code class=\"\" data-line=\"\">RANK()<\/code><\/h3>\n<ul data-start=\"731\" data-end=\"865\">\n<li data-start=\"731\" data-end=\"789\">\n<p data-start=\"733\" data-end=\"789\">Assigns the <strong data-start=\"745\" data-end=\"758\">same rank<\/strong> to rows with <strong data-start=\"772\" data-end=\"788\">equal values<\/strong>.<\/p>\n<\/li>\n<li data-start=\"790\" data-end=\"865\">\n<p data-start=\"792\" data-end=\"865\"><strong data-start=\"792\" data-end=\"818\">Skips the next rank(s)<\/strong> after a tie, which causes <strong data-start=\"845\" data-end=\"853\">gaps<\/strong> in ranking.<\/p>\n<\/li>\n<\/ul>\n<h2 data-start=\"7793\" data-end=\"7859\"><span style=\"font-size: 16px;\">What is the difference between LEFT JOIN and RIGHT JOIN?<\/span><\/h2>\n<p data-start=\"152\" data-end=\"189\"><strong>LEFT JOIN (or LEFT OUTER JOIN)<\/strong><\/p>\n<ul data-start=\"191\" data-end=\"382\">\n<li data-start=\"191\" data-end=\"282\">\n<p data-start=\"193\" data-end=\"282\">Returns <strong data-start=\"201\" data-end=\"233\">all rows from the left table<\/strong>, and the <strong data-start=\"243\" data-end=\"281\">matching rows from the right table<\/strong>.<\/p>\n<\/li>\n<li data-start=\"283\" data-end=\"382\">\n<p data-start=\"285\" data-end=\"382\">If there is <strong data-start=\"297\" data-end=\"309\">no match<\/strong> in the right table, NULLs are returned for columns from the right table.<\/p>\n<\/li>\n<\/ul>\n<p data-start=\"757\" data-end=\"796\"><strong>RIGHT JOIN (or RIGHT OUTER JOIN)<\/strong><\/p>\n<ul data-start=\"798\" data-end=\"987\">\n<li data-start=\"798\" data-end=\"889\">\n<p data-start=\"800\" data-end=\"889\">Returns <strong data-start=\"808\" data-end=\"841\">all rows from the right table<\/strong>, and the <strong data-start=\"851\" data-end=\"888\">matching rows from the left table<\/strong>.<\/p>\n<\/li>\n<li data-start=\"890\" data-end=\"987\">\n<p data-start=\"892\" data-end=\"987\">If there is <strong data-start=\"904\" data-end=\"916\">no match<\/strong> in the left table, NULLs are returned for columns from the left table.<\/p>\n<\/li>\n<\/ul>\n<table>\n<thead>\n<tr>\n<th>Feature<\/th>\n<th>LEFT JOIN<\/th>\n<th>RIGHT JOIN<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Includes all\u2026<\/td>\n<td>Rows from <strong>left<\/strong> table<\/td>\n<td>Rows from <strong>right<\/strong> table<\/td>\n<\/tr>\n<tr>\n<td>NULLs in\u2026<\/td>\n<td>Right table (if no match)<\/td>\n<td>Left table (if no match)<\/td>\n<\/tr>\n<tr>\n<td>Use case<\/td>\n<td>When you want <strong>everything from left<\/strong><\/td>\n<td>When you want <strong>everything from right<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 data-start=\"8128\" data-end=\"8183\">How do you back up a database in SQL Server?<\/h3>\n<p data-start=\"0\" data-end=\"177\">Backing up a database in <strong data-start=\"25\" data-end=\"39\">SQL Server<\/strong> is a critical task to ensure data safety. You can back up a database using <strong data-start=\"115\" data-end=\"154\">SQL Server Management Studio (SSMS)<\/strong> or <strong data-start=\"158\" data-end=\"176\">T-SQL commands<\/strong>.<\/p>\n<div class=\"contain-inline-size rounded-2xl relative bg-token-sidebar-surface-primary\">\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\">\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">BACKUP DATABASE dbname TO DISK = &#039;C:\\backup.bak&#039;<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<\/div>\n<\/div>\n<h3 data-start=\"8251\" data-end=\"8289\">What is an identity column?<\/h3>\n<p data-start=\"0\" data-end=\"219\">An <strong data-start=\"3\" data-end=\"22\">identity column<\/strong> is a special type of column in a database table that <strong data-start=\"76\" data-end=\"126\">automatically generates a unique numeric value<\/strong> for each new row inserted into the table. It\u2019s often used to create <strong data-start=\"195\" data-end=\"218\">unique primary keys<\/strong>.<\/p>\n<p data-start=\"221\" data-end=\"262\"><strong>Key Features of an Identity Column:<\/strong><\/p>\n<ul data-start=\"264\" data-end=\"587\">\n<li data-start=\"264\" data-end=\"379\">\n<p data-start=\"266\" data-end=\"379\"><strong data-start=\"266\" data-end=\"294\">Auto-incremented values:<\/strong> You don\u2019t need to insert a value manually; the database automatically increments it.<\/p>\n<\/li>\n<li data-start=\"380\" data-end=\"466\">\n<p data-start=\"382\" data-end=\"466\"><strong data-start=\"382\" data-end=\"410\">Starts from a seed value<\/strong> (e.g., 1), and <strong data-start=\"426\" data-end=\"455\">increases by an increment<\/strong> (e.g., 1).<\/p>\n<\/li>\n<li data-start=\"467\" data-end=\"534\">\n<p data-start=\"469\" data-end=\"534\">Used to <strong data-start=\"477\" data-end=\"503\">uniquely identify rows<\/strong> (commonly as the primary key).<\/p>\n<\/li>\n<li data-start=\"535\" data-end=\"587\">\n<p data-start=\"537\" data-end=\"587\"><strong data-start=\"537\" data-end=\"565\">Only one identity column<\/strong> per table is allowed.<\/p>\n<\/li>\n<\/ul>\n<h3 data-start=\"8327\" data-end=\"8365\">What are advantages of SQL?<\/h3>\n<ul data-start=\"8366\" data-end=\"8486\">\n<li data-start=\"8366\" data-end=\"8383\">\n<p data-start=\"8368\" data-end=\"8383\">Easy to learn<\/p>\n<\/li>\n<li data-start=\"8384\" data-end=\"8418\">\n<p data-start=\"8386\" data-end=\"8418\">Powerful querying capabilities<\/p>\n<\/li>\n<li data-start=\"8419\" data-end=\"8448\">\n<p data-start=\"8421\" data-end=\"8448\">Widely used and supported<\/p>\n<\/li>\n<li data-start=\"8449\" data-end=\"8486\">\n<p data-start=\"8451\" data-end=\"8486\">High performance for large datasets<\/p>\n<\/li>\n<\/ul>\n<h2><strong>Additional Bonus Basic SQL interview questions and answers<\/strong><\/h2>\n<h3><strong>What is the BETWEEN operator in SQL?<\/strong><\/h3>\n<p>The <strong data-start=\"4\" data-end=\"17\"><code class=\"\" data-line=\"\">BETWEEN<\/code><\/strong> operator in SQL is used to filter the result set within a certain <strong data-start=\"84\" data-end=\"103\">range of values<\/strong>. It checks if a given value falls <strong data-start=\"138\" data-end=\"160\">between two values<\/strong> (inclusive).<\/p>\n<p>Syntax:<\/p>\n<div class=\"code-embed-wrapper\"> <pre class=\"language-sql code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-sql code-embed-code\">SELECT column_name<br\/>FROM table_name<br\/>WHERE column_name BETWEEN value1 AND value2;<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div>\n<h3><strong>What is DDL?<\/strong><\/h3>\n<p data-start=\"0\" data-end=\"207\"><strong data-start=\"0\" data-end=\"7\">DDL<\/strong> stands for <strong data-start=\"19\" data-end=\"47\">Data Definition Language<\/strong>. It is a subset of SQL (Structured Query Language) used to define and manage the <strong data-start=\"129\" data-end=\"142\">structure<\/strong> of database objects such as tables, schemas, indexes, and views.<\/p>\n<h3 data-start=\"214\" data-end=\"244\"><strong data-start=\"221\" data-end=\"244\">Key Features of DDL<\/strong><\/h3>\n<ul data-start=\"245\" data-end=\"406\">\n<li data-start=\"245\" data-end=\"288\">\n<p data-start=\"247\" data-end=\"288\">Defines database <strong data-start=\"264\" data-end=\"288\">schema and structure<\/strong><\/p>\n<\/li>\n<li data-start=\"289\" data-end=\"352\">\n<p data-start=\"291\" data-end=\"352\">Automatically <strong data-start=\"305\" data-end=\"316\">commits<\/strong> the changes (cannot be rolled back)<\/p>\n<\/li>\n<li data-start=\"353\" data-end=\"406\">\n<p data-start=\"355\" data-end=\"406\">Affects how data is <strong data-start=\"375\" data-end=\"385\">stored<\/strong>, not the data itself<\/p>\n<\/li>\n<\/ul>\n<h3><strong>What is DML?<\/strong><\/h3>\n<p data-start=\"0\" data-end=\"239\"><strong data-start=\"0\" data-end=\"36\">DML (Data Manipulation Language)<\/strong> is a subset of SQL (Structured Query Language) used to <strong data-start=\"92\" data-end=\"111\">manipulate data<\/strong> stored in relational databases. DML commands are used to <strong data-start=\"169\" data-end=\"179\">insert<\/strong>, <strong data-start=\"181\" data-end=\"191\">update<\/strong>, <strong data-start=\"193\" data-end=\"203\">delete<\/strong>, and <strong data-start=\"209\" data-end=\"221\">retrieve<\/strong> data from tables.<\/p>\n<p data-start=\"246\" data-end=\"280\"><strong>Common DML Commands in SQL:<\/strong><\/p>\n<div class=\"_tableContainer_80l1q_1\">\n<div class=\"_tableWrapper_80l1q_14 group flex w-fit flex-col-reverse\" tabindex=\"-1\">\n<table class=\"w-fit min-w-(--thread-content-width)\" data-start=\"282\" data-end=\"526\">\n<thead data-start=\"282\" data-end=\"307\">\n<tr data-start=\"282\" data-end=\"307\">\n<th data-start=\"282\" data-end=\"292\" data-col-size=\"sm\">Command<\/th>\n<th data-start=\"292\" data-end=\"307\" data-col-size=\"sm\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody data-start=\"333\" data-end=\"526\">\n<tr data-start=\"333\" data-end=\"386\">\n<td data-start=\"333\" data-end=\"344\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">SELECT<\/code><\/td>\n<td data-start=\"344\" data-end=\"386\" data-col-size=\"sm\">Retrieves data from one or more tables<\/td>\n<\/tr>\n<tr data-start=\"387\" data-end=\"436\">\n<td data-start=\"387\" data-end=\"398\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">INSERT<\/code><\/td>\n<td data-start=\"398\" data-end=\"436\" data-col-size=\"sm\">Adds new rows of data into a table<\/td>\n<\/tr>\n<tr data-start=\"437\" data-end=\"485\">\n<td data-start=\"437\" data-end=\"448\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">UPDATE<\/code><\/td>\n<td data-start=\"448\" data-end=\"485\" data-col-size=\"sm\">Modifies existing data in a table<\/td>\n<\/tr>\n<tr data-start=\"486\" data-end=\"526\">\n<td data-start=\"486\" data-end=\"497\" data-col-size=\"sm\"><code class=\"\" data-line=\"\">DELETE<\/code><\/td>\n<td data-start=\"497\" data-end=\"526\" data-col-size=\"sm\">Removes data from a table<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3><strong>What is DCL?<\/strong><\/h3>\n<p data-start=\"0\" data-end=\"226\"><strong data-start=\"0\" data-end=\"31\">DCL (Data Control Language)<\/strong> is a subset of SQL (Structured Query Language) used to control access to data within a database. It is primarily concerned with the <strong data-start=\"164\" data-end=\"194\">permissions and privileges<\/strong> related to database operations.<\/p>\n<p data-start=\"0\" data-end=\"226\"><strong>Key DCL Commands<\/strong><\/p>\n<ul>\n<li data-start=\"0\" data-end=\"226\">GRANT<\/li>\n<li data-start=\"0\" data-end=\"226\">REVOKE<\/li>\n<\/ul>\n<h3 data-start=\"0\" data-end=\"226\"><strong>What is TCL?<\/strong><\/h3>\n<p data-start=\"66\" data-end=\"363\">TCL commands are used to <strong data-start=\"91\" data-end=\"114\">manage transactions<\/strong> in a database. A <strong data-start=\"132\" data-end=\"147\">transaction<\/strong> is a sequence of one or more SQL statements that are executed as a single unit of work. These commands help ensure <strong data-start=\"263\" data-end=\"281\">data integrity<\/strong> and consistency, especially when multiple changes are being made to the database.<\/p>\n<p data-start=\"66\" data-end=\"363\"><strong>Common TCL Commands<\/strong><\/p>\n<ul>\n<li data-start=\"66\" data-end=\"363\">COMMIT<\/li>\n<li data-start=\"66\" data-end=\"363\">ROLLBACK<\/li>\n<li data-start=\"66\" data-end=\"363\">SAVEPOINT<\/li>\n<li data-start=\"66\" data-end=\"363\">ROLLBACK TO SAVEPOINT<\/li>\n<li data-start=\"66\" data-end=\"363\">SET TRANSACTION<\/li>\n<\/ul>\n<h2 data-start=\"151\" data-end=\"215\">Final Thoughts on the <strong data-start=\"178\" data-end=\"215\">Basics of SQL Interview Questions<\/strong><\/h2>\n<p>Mastering these <strong>basic SQL interview questions, basic SQL interview questions and answers, and basics of SQL interview questions<\/strong> is a vital step for anyone aspiring to enter the data or software industry. Whether you are applying for a database administrator role, a software developer position, or a data analyst job, a solid understanding of SQL will give you a strong edge.<\/p>\n<p><strong>Want to dive deeper into SQL?<\/strong> Explore our full <a href=\"https:\/\/www.kaashivinfotech.com\/sql-server-course-in-chennai\/\">SQL Course for Beginners<\/a> that includes hands-on projects, real-world datasets, and certification upon completion. Learn how to write complex queries, optimize database performance, and confidently clear your next SQL interview!<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re preparing for your next tech interview, mastering the basic SQL interview questions\u00a0is crucial. SQL, or Structured Query Language, is a powerful and standardized programming language designed for managing and manipulating relational databases. It serves as a means to interact with databases, enabling users to create, retrieve, update, and delete data. SQL is widely [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":25774,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[724],"tags":[742,744,746,749,754,740,741,751,748,745,747,743,752,750,753],"class_list":["post-1483","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interview-questions","tag-interview-questions-sql","tag-interview-questions-sql-basic","tag-sql-basic-questions","tag-sql-interview","tag-sql-interview-preparation","tag-sql-interview-questions","tag-sql-interview-questions-and-answers","tag-sql-interview-questions-and-answers-for-experienced","tag-sql-interview-questions-and-answers-for-freshers","tag-sql-interview-questions-for-beginners","tag-sql-interview-questions-for-experienced","tag-sql-interview-questions-for-freshers","tag-sql-questions","tag-sql-server-interview-questions","tag-top-sql-interview-questions"],"_links":{"self":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/1483","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/comments?post=1483"}],"version-history":[{"count":0,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/posts\/1483\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media\/25774"}],"wp:attachment":[{"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/media?parent=1483"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/categories?post=1483"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kaashivinfotech.com\/blog\/wp-json\/wp\/v2\/tags?post=1483"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}