Junior — Middle
Explain what a record's unique identifier in a database table is.
sobes.tech AI
Answer from AI
A unique record identifier in a database table is a field (or set of fields) whose value uniquely identifies each record in the table. This is usually a primary key.
For example, in a users table, a unique identifier could be the id field, which contains a unique number or UUID for each user. This allows for quick lookup, update, or deletion of a specific record without confusion.
Example in Node.js using MongoDB:
const { ObjectId } = require('mongodb');
// Creating a new unique identifier
const newId = new ObjectId();
// Using it in a document
const user = {
_id: newId,
name: 'Ivan',
email: 'ivan@example.com'
};
// In MongoDB, the _id field is by default a unique identifier
Thus, a unique identifier guarantees that each record in the table can be unambiguously identified.