database objects
database objects
Tables:
• In SQL Server, data is primarily stored in tables. Each table consists of rows
(records) and columns (fields).
• Fundamental data structures.
• Organize data into rows and columns.
• Example:
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
FirstName NVARCHAR(50),
LastName NVARCHAR(50),
Address NVARCHAR(100),
PhoneNumber VARCHAR(20)
);
Various Table Types Comparison
• Heap Table:
• A table without a clustered index.
• Data is stored unordered.
• Suitable for temporary data but slower for queries.
• Clustered Table:
• A table with a clustered index.
• Rows are stored in sorted order based on the index key.
• Improves performance for range-based queries.
• Partitioned Table:
• Divides large tables into smaller, more manageable pieces (partitions).
• Each partition can be stored in separate filegroups
Indexes:
• Data structures that improve the speed of data retrieval.
• Create shortcuts to specific data, making queries faster.
Example:
CREATE INDEX idx_CustomerID ON Customers(CustomerID);
Views
• Logical, virtual tables that display data from one or more tables.
• Used for simplifying queries, security, and abstraction.
• Example:
CREATE VIEW EmployeeDetails AS
SELECT EmployeeID, FirstName, LastName, Department
FROM Employees;
Stored Programs:
• Include stored procedures, functions, and triggers.
• Stored Procedures:
• Precompiled SQL code for reusable operations.