Reputation: 33
I have to create a view in SQL that has a set of default values without creating any tables, and I don't know if it is possible or not? Maybe something like this:
CREATE VIEW PersonalView
AS
SELECT *
FROM (VALUES('Sara', 'Moradi', '22'))
Upvotes: 0
Views: 811
Reputation: 453057
Another variant you can use is
CREATE VIEW PersonalView (first_name, last_name, age)
AS
SELECT 'Sara', 'Moradi', 22
Upvotes: 0
Reputation: 175606
It is almost correct. You need to add aliases:
CREATE VIEW PersonalView
AS
SELECT * FROM ( VALUES ('Sara', 'Moradi', '22')) s(fist_name, last_name, age);
Upvotes: 2
Reputation: 311163
In SQL-Server you can write a query without a from
clause, but note you'll need to give the literals column names. E.g.:
CREATE VIEW PersonalView AS SELECT 'Sara' AS name, 'Moradi' AS last_name, '22' AS age
Upvotes: 1