Question
Difference between Store procedure & View ?
A
Anonymous
December 21, 2025
66
Answer
View
- A View is a virtual table created using a SQL SELECT statement.
- It does not store data itself (except indexed/materialized views); it only stores the query.
Key Points
- Read-only in most cases
- Simplifies complex queries
- Improves readability and reuse
- Enforces data abstraction and security
Example
CREATE VIEW active_employees AS
SELECT emp_id, name, dept_id
FROM employee
WHERE status = 'ACTIVE';
Stored Procedure
A Stored Procedure is a compiled set of SQL statements stored in the database that can:
- Perform CRUD operations
- Contain business logic
- Accept input/output parameters
- Handle transactions and error handling
Example
CREATE PROCEDURE create_employee(
IN p_name VARCHAR(100),
IN p_dept_id INT
)
BEGIN
INSERT INTO employee(name, dept_id)
VALUES (p_name, p_dept_id);
SELECT *FROM employeel
END;
In summary, A View is a virtual, read-only table used for simplified data access and reporting, while a Stored Procedure is an executable database program used for complex logic, transactions, and data manipulation.
JuniorDatabase
Loading comments...