Загрузка...

SQL Interview Question #10 | What is a Composite Key?

SQL Interview Question #10

What is a Composite Key in SQL?

A Composite Key is a combination of two or more columns that together uniquely identify a row in a table.

Individually, the columns may contain duplicate values.

But when combined, they create a unique record.

✅ Combination of multiple columns
✅ Uniquely identifies each row
✅ Used when one column alone is not sufficient

Example:

OrderDetails Table

## OrderID | ProductID

101 | 1
101 | 2
102 | 1
102 | 3

Here:

❌ OrderID is not unique

❌ ProductID is not unique

✅ OrderID + ProductID is unique

Therefore, (OrderID, ProductID) is a Composite Key.

💡 Interview Tip:

When one column cannot uniquely identify a row, combine multiple columns to create a Composite Key.

🔔 Subscribe for daily SQL interview questions and SQL Server interview preparation.

#sql #sqlserver #mssql #compositekey #database #sqlinterview #interviewquestions #learnsql #dba #softwareengineer

Видео SQL Interview Question #10 | What is a Composite Key? канала Krish for tech
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять