sql / beginner
Snippet
Enhancing Database Security with Views
A view provides a restricted virtual table that exposes only non-sensitive columns, preventing unauthorized access to confidential fields like passwords or social security numbers.
snippet.sql
sql
1
2
3
CREATE VIEW public_user_profiles ASSELECT user_id, username, created_atFROM users;
Breakdown
1
CREATE VIEW public_user_profiles AS
Creates a virtual table named public_user_profiles.
2
SELECT user_id, username, created_at
Chooses only the safe, public columns to be exposed.
3
FROM users;
Points to the underlying users table containing the raw data.