0% found this document useful (0 votes)
2 views

database objects

The document outlines core data objects in SQL Server, focusing on tables, indexes, views, and stored programs. It describes various table types such as heap, clustered, and partitioned tables, along with their characteristics and use cases. Additionally, it covers the creation of indexes for faster data retrieval and the implementation of stored procedures and functions for reusable SQL operations.

Uploaded by

sammbilizi1
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

database objects

The document outlines core data objects in SQL Server, focusing on tables, indexes, views, and stored programs. It describes various table types such as heap, clustered, and partitioned tables, along with their characteristics and use cases. Additionally, it covers the creation of indexes for faster data retrieval and the implementation of stored procedures and functions for reusable SQL operations.

Uploaded by

sammbilizi1
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Core Data 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.

CREATE PROCEDURE GetEmployeeByID @ID INT


AS
SELECT * FROM Employees WHERE EmployeeID = @ID;
• Functions:
• Return single values or tables.
CREATE FUNCTION GetFullName(@FirstName NVARCHAR(50), @LastName
NVARCHAR(50))
RETURNS NVARCHAR(100)
AS
BEGIN
RETURN @FirstName + ' ' + @LastName;
END;

You might also like