Questions tagged [sql-view]

A database view is a stored query. Its output automatically updates as underlying table data changes.

A database view does not store data as tables (temporary or otherwise) do; rather, it is a saved query that can be recalled and reused. Its output automatically updates as underlying table data changes.

Reference

990 questions
4
votes
1 answer

Create navigation/association from table to view in EF 4.0

I have a Container table with ContainerId as PK (int), and a (readonly) view vwBlobRef with a BlobRefId column set as PK and ContainerId as FK. By the way, I have to manually set the BlobRefId as the Entity Key for the view... Now I want to…
4
votes
4 answers

Problem updating a sql view

I am having a problem with a sql view. My actual views encompass several joins, but for the purposes of my question I will demonstrate the issue with smaller examples. Say I have the views… create view A as select Id as IdC from…
John Livermore
  • 30,235
  • 44
  • 126
  • 216
4
votes
3 answers

MariaDB create view changes the SELECT to a different (incorrect) query

I have a query I would like as a view in MariaDB 10.3(win), however when I attempt to create such view it is being changed to a different (and incorrect) one, removing parentheses: create or replace view v_ReceiptSumByVAT as select VAT,…
wondra
  • 3,271
  • 3
  • 29
  • 48
4
votes
1 answer

Hasura computed fields vs. Postgres generated columns vs. Postgres views

We're implementing an e-commerce data model and struggle to decide between Postgres generated columns, Hasura computed fields, and Postgres views. As a simplification, we have two…
Philip Seyfi
  • 929
  • 1
  • 10
  • 24
4
votes
1 answer

SQL View with Parameter in PostgreSQL, best way to prevent SQL error on runtime?

Is it possible to create view with parameter in PostgreSQL? the problem was, there probably unverified SQL syntax in our backend services that can cause an internal server error, so probably I'll need to convert every queries to views? Something…
Kokizzu
  • 24,974
  • 37
  • 137
  • 233
4
votes
3 answers

Dynamic column names

Is it possible to create a view (not stored procedure) with dynamic column names based on another table? For example: Code: CodeId|Description ------------------ 1|Title …
Nelson Rothermel
  • 9,436
  • 8
  • 62
  • 81
4
votes
1 answer

I have a view that runs fine when executed, but when I try to open it in design mode, it throws a parsing error

I don't have enough reputation to post a screen capture, so I'll do my best to explain what's happening. As I said in the title, it is a view that executes just fine when you run it normally. When I try to open it using design view, it throws this…
4
votes
2 answers

SQL Select two max rows from same table and joining with third table

Two tables in the mix: items | item_id | user_id | data | ---------------------------- | 10 | 100 | A | | 11 | 100 | C | | 12 | 101 | E | | 13 | 101 | G | item_detail | id | item_id | ignore | detail1…
4
votes
1 answer

Check if a given DB object used in Oracle?

Hi does any one know how to check if a given DB object (Table/View/SP/Function) is used inside Oracle. For example to check if the table "A" is used in any SP/Function or View definitions. I am trying to cleanup unused objects in the database. I…
budsiya
  • 540
  • 3
  • 14
  • 22
4
votes
3 answers

Can SQL view have infinite number of rows? (Repeating schedule, each row a day?)

Can I have a view with an infinite number of rows? I don't want to select all the rows at once, but is it possible to have a view that represents a repeating weekly schedule, with rows for any date? I have a database with information about…
Adam Mackler
  • 1,980
  • 1
  • 18
  • 32
4
votes
3 answers

MySQL Views: Referencing one calculated field (by name) in another calculated field

How can I define a view that has two calculated fields, for instance... ('TableName'.'BlueSquares' + 'TableName'.'RedSquares') AS TotalSquares, ('TableName'.'BlueCirles' + 'TableName'.'RedCircles') AS TotalCircles ... and create a third calculated…
Alan M.
  • 1,309
  • 2
  • 19
  • 29
4
votes
1 answer

Update/Insert into View wia Trigger

It occurred in my project that I had to extend an existing table with a few more columns. Unfortunately I can't alter or drop/recreate it, so I just chose to create another table with a 1:1-Relationship and merge them in a view with…
Qohelet
  • 1,459
  • 4
  • 24
  • 41
4
votes
1 answer

SQL Server views vs LINQ to entities queries with EF Code First

Question is related only to Entity Framework 5 code-first. What is the better option (performance and scalability): Create SQL Server views, treat them as DbSets in your DbContext. Create custom classes that represent view models, use Linq to…
Admir Tuzović
  • 10,997
  • 7
  • 35
  • 71
4
votes
2 answers

MySQL - create view using subquery in FROM clause

I want to create view in MySQL using a subquery CREATE OR REPLACE VIEW `V_TASK_TRANSFER` (`REF_ID`, `DATE_CREATE`, `DATE_TRX`, `ACCOUNT_NO`, `TO_ACCOUNT_NO`, `TO_NAME`, `CURRENCY_CODE`, `AMOUNT`, `TASK_TYPE`, `NAME_E`, `NAME_I`, `REF_NO`,…
Rifqi Fitriady
  • 93
  • 1
  • 3
  • 9
4
votes
2 answers

Where & Top interaction in SQL Server View

Do you know how to persuade SQL Server to consider WHERE clauses inside the view? It looks like SQL Server is running just my view, evaluating the TOP 1, then applying the "where id=N" clause to filter the view's result set. Example: create table…
John Greve
  • 41
  • 2