Загрузка...

SQL Top 10 Interview question: #sql #databaseconcepts #sqlinterview #programming #dataanlysis

Consider the following SQL query:

ALTER TABLE employees
ADD salary INT NOT NULL;

Assume the employees table already contains 1 million records.

Question: Will this query execute successfully? Why or why not?

Answer:
The query will fail because existing rows do not have values for the new salary column. Since the column is defined as NOT NULL, the database cannot populate existing records with NULL values.

To make this work, you can:

Add a default value:

ALTER TABLE employees
ADD salary INT NOT NULL DEFAULT 0;

Add the column as nullable first:

ALTER TABLE employees
ADD salary INT NULL;

Then update the values and later change the column to NOT NULL.
#sqlinterview #databaseconcepts #sqlinterviewquestionsandanswers #Databasedeveloper
#SQLinHindi
#sqldeveloper
SQL consecutive login streaks
15 SQL Interview Questions TO GET YOU HIRED in 2026 | SQL Interview Questions & Answers
sql interview questions and answers in Hindi
SQL Interview Questions and Answers for Data Analysts (2026)

Видео SQL Top 10 Interview question: #sql #databaseconcepts #sqlinterview #programming #dataanlysis канала SQLCodeClarity
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять