sql-view

Using T-SQL AVG or taking Average after results returned using LINQ

I have a stored procedure that uses a view to pull 6 averages. The SQL database is SQL Server 2000. When I run it in the Query analyzer, it takes roughly 9 seconds. What can I do to get better performance? Should I return the rows using LINQ and determine an average that way? Will it be faster? Here's an example of my current sproc: cr...

A SQL story in 2 parts - Are SQL views always good and how can I solve this example?

Hiya, I'm building a reporting app, and so I'm crunching an awful lot of data. Part of my approach to creating the app in an agile way is to use SQL views to take the strain off the DB if multiple users are all bashing away. One example is: mysql_query("CREATE VIEW view_silverpop_clicks_baby_$email AS SELECT view_email_baby_posit...

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 field that's based on the first two calculated fields, as in... ('ViewName'.'TotalSqu...

Slow response when querying a View - Using Linq to SQL

I have the following view: SELECT poHeader.No_ AS PONumber, poHeader.[Buy-from Vendor No_] AS VendorNumber, poHeader.[Document Date] AS DocumentDate, vendor.Name AS VendorName, vendor.Contact AS VendorContact, vendor.[E-Mail] AS VendorEmail, vendor.Address AS VendorAddress, vendor.[Address 2] AS VendorAddress2, vendor.City ...

MySQL table view limitations

Are there any limitations in the functionality of SQL Views for MySQL? ex: Can you create a table view using 'JOIN' commands? ...

Performing string concatenation from rows of data in a TSQL view (pivot?)

I'd like to create a view in SQL Server that combines several pieces of database metadata. One piece of metadata I want lives in the sys.syscomments table - the relevent columns are as follows: id colid text ---- ------ ------------- 1001 1 A comment. 1002 1 This is a lo 1002 2 ng comment. 1003 1 This is an e...

[MySQL]: table view or actual table. (tracing a primary key)

Hi, I have a Database that has the following relations: Transaction->Purchase->Item->Schedule Transaction - self explanitory Purchase - any purchase info that relates to the item being purchased (quantity, if the user purchases more than one item). A given Transaction can have more than one Purchase_ID tied to it. Item - Stores Item ...

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 tried the query select * from all_source WHERE TEXT like '%A%' (A is the table name). Do y...

mysql create view only if it doesn't already exist

How do I create a view only if it doesn't exist. If it does exist, I want to drop the view and redefine it. I also want no warnings or errors. ...

creating django model for existing database/sql view?

I have inserted a definition for a view in $template_dir/sql/$someTableName.sql file. (create or replace view) so every time I run syncdb, the db views are created. Can I create in models.py a python class which accesses that view? Is it better practice to just use python's raw sql functionality instead? ---EDIT--- Another problem I ...

Using views for access control in PostgreSQL

I have a schema of tables whose contents basically boil down to: A set of users A set of object groups An access control list (acl) indicating what users have access to what groups A set of objects, each of which belongs to exactly one group. I want to create a simple application that supports access control. I'm thinking views woul...

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 INT, NULL. In a view, I want to return a row for each row in Product, with a BIT column se...

Can I concatenate a virtual column in a view?

Unfortunately, I have plaintext passwords in a database. I want to pass these plaintext values around as little as possible for, say, comparisons and updates. To this end, I'm trying to create a view of my Users table that excludes the plaintext passwords and instead provides a hashed value of that password. Here's my current SQL Serv...

PostgreSQL Views: Referencing one calculated field in another calculated field

I have the same question as #1895500, but with PostgreSQL not MySQL. How can I define a view that has a calculated field, for example: (mytable.col1 * 2) AS times_two ... and create another calculated field that's based on the first one: (times_two * 2) AS times_four ...? ...

SQL. Sorting by a field

I have created a simple view consisting of 3 tables in SQL. By right clicking and selecting Design, in the Object explorer table, i modified my custom view. I just added sortby asc in a field. The problem is that the changes are not reflected in the outout of the View. After saving the view, and selecting Open view the sort is not disp...

How do MySQL views work?

When I create a view I am basically like making a new table that will automatically be transacted upon when data in one of the tables it joins changes? Also why can't I use subqueries in my view???? ...

MySQL: Data query from multiple tables with views

I want to create a query result page for a simple search, and i don't know , should i use views in my db, would it be better if i would write a query into my code with the same syntax like i would create my view. What is the better solution for merging 7 tables, when i want to build a search module for my site witch has lots of users an...

How to create view from more than one table in MS Sql Server database?

I have to create a view from more than one table in MS Sql Server database, but i am not able to get the correct syntax for the same. need help. thanks. ...

SELECT statement for a VIEW in MySQL not returning all the wanted rows

I need help with my MySQL query: CREATE OR REPLACE DEFINER = CURRENT_USER VIEW users_phpscheduleit AS SELECT u.uid AS memberid, pass AS password, mail AS email, pv1.value AS fname, pv2.value AS lname, pv3.value AS phone, e_add, e_mod, e_de...

Entity Framework 4.0 & null fields in Views

We're adding some views to our entity framework model. Some fields in these views are nullable datetime2 datatypes in our sql server 2k8 db and the edmx is incorrectly showing these fields as being not null. Is this a known issue? When I try to change them to not null it still throws the same error - because it appears as if the ssdl is...