Common Database Objects
Common Database Objects in Azure relational databases are fundamental structures used to store, manage, and manipulate data efficiently. Here are the key objects: **1. Tables:** Tables are the core database objects that store data in rows and columns. Each row represents a unique record, and each column represents a field with a specific data type. Tables enforce structure through schemas, ensuring data consistency and integrity. **2. Views:** Views are virtual tables based on the result of a SQL query. They don't store data themselves but provide a way to simplify complex queries, restrict access to specific data, and present data in a customized format. Views enhance security by exposing only necessary columns or rows to users. **3. Indexes:** Indexes improve the speed of data retrieval operations on tables. They work similarly to a book's index, allowing the database engine to find data without scanning every row. While indexes boost read performance, they can slightly slow down write operations due to the overhead of maintaining the index structure. **4. Stored Procedures:** Stored procedures are precompiled collections of SQL statements stored in the database. They encapsulate business logic, promote code reuse, improve performance through precompilation, and enhance security by controlling data access through parameterized operations. **5. Functions:** Functions are reusable blocks of SQL code that accept parameters, perform calculations or operations, and return a value or a table. They help simplify complex computations and can be used within queries. **6. Triggers:** Triggers are special stored procedures that automatically execute in response to specific events on a table, such as INSERT, UPDATE, or DELETE operations. They are commonly used to enforce business rules, maintain audit trails, and ensure data integrity. These database objects work together to create a robust, efficient, and secure relational database system in Azure, supporting services like Azure SQL Database, Azure Database for MySQL, and Azure Database for PostgreSQL.
Common Database Objects – DP-900 Exam Guide
Understanding common database objects is foundational to working with relational databases on Azure and is a key topic in the Microsoft DP-900: Azure Data Fundamentals exam. These objects form the building blocks of any relational database system. Whether you are designing a database, querying data, or managing security, you will interact with these objects daily. For the DP-900 exam, Microsoft expects you to identify, describe, and differentiate between these objects confidently.
What Are Common Database Objects?
Common database objects are the structural components that make up a relational database. The primary objects you need to know for the DP-900 exam include:
1. Tables
Tables are the core objects in a relational database. They store data in rows (records) and columns (fields). Each table represents an entity, such as Customers, Orders, or Products. Each column has a defined data type (e.g., INT, VARCHAR, DATE), and each row represents a single instance of that entity. Tables enforce structure through schemas.
2. Views
A view is a virtual table based on the result of a SQL query. It does not store data physically; instead, it provides a saved query that can be referenced like a table. Views are useful for:
- Simplifying complex queries
- Restricting access to specific columns or rows (security)
- Presenting data in a specific format without modifying the underlying tables
3. Indexes
An index is a data structure that improves the speed of data retrieval operations on a table. Think of it like an index in a book — it helps you find information quickly without scanning every page. There are two main types:
- Clustered Index: Sorts and stores the actual data rows in the table based on the index key. A table can have only one clustered index.
- Non-Clustered Index: Creates a separate structure that contains the index key and a pointer to the data row. A table can have multiple non-clustered indexes.
Indexes speed up read operations (SELECT) but can slow down write operations (INSERT, UPDATE, DELETE) because the index must also be updated.
4. Stored Procedures
A stored procedure is a precompiled collection of one or more SQL statements stored in the database. They can accept input parameters, execute logic, and return results. Benefits include:
- Reusability of code
- Improved performance (precompiled execution plans)
- Enhanced security (users can execute the procedure without direct access to underlying tables)
- Reduced network traffic
5. Functions
Functions are similar to stored procedures but are designed to return a value. There are two types:
- Scalar Functions: Return a single value (e.g., a calculated total).
- Table-Valued Functions: Return a table result set.
Functions can be used within SQL statements, such as in SELECT or WHERE clauses, unlike stored procedures.
6. Triggers
A trigger is a special type of stored procedure that automatically executes in response to certain events on a table or view, such as INSERT, UPDATE, or DELETE operations. Triggers are commonly used for:
- Enforcing business rules
- Auditing changes to data
- Maintaining data integrity across related tables
How Do These Objects Work Together?
In a relational database, tables hold the actual data. Views provide controlled, simplified access to that data. Indexes optimize how quickly data in tables can be retrieved. Stored procedures and functions encapsulate reusable business logic and queries. Triggers automatically enforce rules or perform actions when data changes. Together, these objects enable efficient, secure, and well-organized data management.
How These Objects Apply on Azure
Azure SQL Database, Azure SQL Managed Instance, and Azure Database for PostgreSQL/MySQL all support these common database objects. In Azure SQL Database, for example, you can create tables, define views, build indexes, write stored procedures, create functions, and configure triggers — just as you would in an on-premises SQL Server environment. The DP-900 exam does not require you to write SQL code, but you must understand what each object is and its purpose.
Exam Tips: Answering Questions on Common Database Objects
- Know the definitions: Be able to clearly distinguish between a table, a view, an index, a stored procedure, a function, and a trigger. Exam questions often present a scenario and ask you to identify which object is being described.
- Views vs. Tables: Remember that views do not store data physically. If a question asks about a virtual table or a way to restrict data access without creating a new table, the answer is likely view.
- Indexes and Performance: If a question mentions improving query performance or speeding up data retrieval, think index. Remember that a clustered index physically reorders data and there can be only one per table.
- Stored Procedures vs. Functions: If the scenario describes reusable SQL logic that can be called with parameters, consider stored procedure. If it describes returning a single computed value within a query, think function.
- Triggers and Automation: If a question describes an automatic action that occurs when data is inserted, updated, or deleted, the answer is trigger.
- Watch for distractors: The exam may include options like "constraint" or "schema" — know that constraints enforce rules on data (like PRIMARY KEY or FOREIGN KEY), while schemas are organizational containers for database objects.
- Focus on purpose, not syntax: The DP-900 exam is conceptual. You will not be asked to write SQL code. Focus on understanding what each object does and why you would use it, not the exact syntax to create it.
- Scenario-based questions: Practice mapping real-world scenarios to the correct database object. For example: "A database administrator wants to ensure that every time a row is deleted from the Orders table, a record is written to an AuditLog table." The correct answer is trigger.
- Remember key constraints: While not always categorized as a "database object" in the same way, understand that PRIMARY KEY, FOREIGN KEY, UNIQUE, NOT NULL, CHECK, and DEFAULT are constraints applied to tables to enforce data integrity. These are frequently tested alongside common database objects.
By understanding the role and purpose of each common database object, you will be well-prepared to answer related questions on the DP-900 exam confidently and accurately.
DP-900 - Common Database Objects Example Questions
Test your knowledge of Common Database Objects
Question 1
What primary performance tradeoff characterizes the implementation of a materialized view compared to a standard virtual table in a relational database system?
Question 2
A team is building a small e-commerce database. They need to ensure that every order record is linked to a valid customer record in the customers table. If someone tries to insert an order referencing a customer that does not exist, the database should prevent it. Which database object best achieves this requirement?
Question 3
What specific primary function does an external table serve in a modern relational database architecture?