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
140
votes
9 answers

Entity Framework and SQL Server View

For several reasons that I don't have the liberty to talk about, we are defining a view on our Sql Server 2005 database like so: CREATE VIEW [dbo].[MeterProvingStatisticsPoint] AS SELECT CAST(0 AS BIGINT) AS 'RowNumber', CAST(0 AS BIGINT) AS…
91
votes
3 answers

Table-Valued Function(TVF) vs. View

What's the difference between table-valued functions and views? Is there something you can do with 1 that's hard or impossible to do with the other? Or does the difference lie in efficiency?
Haoest
  • 13,610
  • 29
  • 89
  • 105
91
votes
3 answers

How to make a view column NOT NULL

I'm trying to create a view where I want a column to be only true or false. However, it seems that no matter what I do, SQL Server (2008) believes my bit column can somehow be null. I have a table called "Product" with the column "Status" which is…
René
  • 9,880
  • 4
  • 43
  • 49
85
votes
8 answers

SQL Views - no variables?

Is it possible to declare a variable within a View? For example: Declare @SomeVar varchar(8) = 'something' gives me the syntax error: Incorrect syntax near the keyword 'Declare'.
PositiveGuy
  • 46,620
  • 110
  • 305
  • 471
77
votes
7 answers

Working with SQL views in Entity Framework Core

For example, I have such model: public class Blog { public int BlogId { get; set; } public string Url { get; set; } public BlogImage BlogImage { get; set; } } public class BlogImage { public int BlogImageId { get; set; } public…
Yurii N.
  • 5,455
  • 12
  • 42
  • 66
63
votes
5 answers

Can I use a database view as a model in Django?

i'd like to use a view i've created in my database as the source for my django-view. Is this possible, without using custom sql? ******13/02/09 UPDATE*********** Like many of the answers suggest, you can just make your own view in the database and…
spence91
  • 77,143
  • 9
  • 27
  • 19
44
votes
3 answers

How do MySQL views work?

When I create a view I am basically making a new table that will automatically be transacted upon when data in one of the tables it joins changes; is that correct? Also why can't I use subqueries in my view?
John Nall
  • 839
  • 1
  • 7
  • 11
42
votes
7 answers

Select Columns of a View

I'm attempting to select the column names of a view in a similar way as selecting from information_schema.columns. I can't seem to find a way to do this. Has anyone else done this before or know if it is even possible?
steventnorris
  • 5,656
  • 23
  • 93
  • 174
35
votes
5 answers

Create view with primary key?

I create a view with following codes SELECT CONVERT(NVARCHAR, YEAR(okuma_tarihi)) + 'T1' AS sno, YEAR(okuma_tarihi) AS Yillar, SUM(toplam_kullanim_T1) AS TotalUsageValue, 'T1' AS UsageType FROM TblSayacOkumalari GROUP BY …
AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197
31
votes
5 answers

SQL - CTE vs VIEW

My question here is what is the difference between CTE and View in SQL. I mean in which case I should use the CTE and which case the View. I know that both are some kind of virtual tables but I can't differentiate their use. I found a similar…
BlackM
  • 3,927
  • 8
  • 39
  • 69
29
votes
4 answers

Create View - Declare a variable

I am creating a view that is using that STUFF function. I want to put the result of STUFF in a variable for my view. The problem I am having is declaring my variable. It gives me the message "Incorrect Syntax near 'DECLARE'. Expecting '(' or…
Ethel Patrick
  • 885
  • 7
  • 18
  • 38
29
votes
4 answers

Error: Could not use view or function because of binding errors

I got read only access to Views and when i am trying to query the View i got this error message. Can anyone help me understand what is the actual problem and how to fix it. FYI.. this is the 1st time i am viewing this table . Here is the error…
swathi
  • 377
  • 2
  • 7
  • 13
24
votes
3 answers

Create database view from django model

I learned sql "view" as a virtual table to facilitate the SQL operations, like MySQL [distributor]> CREATE VIEW CustomerEMailList AS -> SELECT cust_id, cust_name, cust_email -> FROM Customers -> WHERE cust_email IS NOT NULL; Query OK, 0…
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
23
votes
3 answers

How do read-only database views fit into the repository pattern?

Example: Your database has a SQL view named "CustomerOrdersOnHold". This view returns a filtered mix of specific customer and order data fields. You need to fetch data from this view in your application. How does access to such a view fit into the…
22
votes
3 answers

Difference between SQL View and WITH clause

Can anybody in here tell me the difference of VIEW and WITH, as I have searched many placed and I can't find anything about it. My thoughts is that VIEW and WITH are the same, except for VIEWs is saved as a Schema-object, but I can be wrong
The87Boy
  • 877
  • 4
  • 14
  • 32
1
2 3
65 66