Large Views Vs Multiple Small Views
Sep 6, 2007Which is more efficient? One large view that joins >=10 tables, or a few smaller views that join only the tables needed for individual pages?
View 1 RepliesWhich is more efficient? One large view that joins >=10 tables, or a few smaller views that join only the tables needed for individual pages?
View 1 RepliesFellow database developers,I would like to draw on your experience with views. I have a databasethat includes many views. Sometimes, views contains other views, andthose views in turn may contain views. In fact, I have some views inmy database that are a product of nested views of up to 6 levels deep!The reason we did this was.1. Object-oriented in nature. Makes it easy to work with them.2. Changing an underlying view (adding new fields, removing etc),automatically the higher up views inherit this new information. Thismake maintenance very easy.3. These nested views are only ever used for the reporting side of ourapplication, not for the day-to-day database use by the application.We use Crystal Reports and Crystal is smart enough (can't believe Ijust said that about Crystal) to only pull back the fields that arebeing accessed by the report. In other words, Crystal will issue aSelect field1, field2, field3 from ReportingView Where .... eventhough "ReportingView" contains a long list of fields.Problems I can see.1. Parent views generally use "Select * From childview". This meansthat we have to execute a "sp_refreshview" command against all viewswhenever child views are altered.2. Parent views return a lot of information that isn't necessarilyused.3. Makes it harder to track down exactly where the information iscoming from. You have to drill right through to the child view to seethe raw table joins etc.Does anyone have any comments on this database design? I would love tohear your opinions and tales from the trenches.Best regards,Rod.
View 15 Replies View RelatedHi,
I need to regenerate a large view each month which performs a union across a number of partitioned tables. (DB is SQL Server 7)
The select statement for each table within the union is large and cannot be replaced with 'select *'.
One possible approach is to obtain the current view definition from syscomments and append an additonal 'UNION select ... from ...' to the end. However I'm having difficulties getting the full textual definition back into variables with the stored procedure. Getting the view definition from the information schema returns a truncated version.
Is there a way to get the whole of the description back (may be >8k)?
I have similar problems manipulating large text fields within the stored proc. If I try to build the entire view definition each period I hit the problem that EXEC cannot take a TEXT parameter (and a varchar isn't big enough).
There are some (messy) ways around this problem, but has anyone had a similar situation where large statements have have to built up before passing them to an EXEC statement and found a neat solution?
Hello.
Newbie here. I've only been using SQL for about a year now and have some minor questions about sql objects that reference other objects.
We have some views which reference other views in the joins. I will call one the primary view and the one being referenced in the joins as the secondary view.
Recently we made changes to the secondary view.
After which the primary views which referenced it would not work because of this change and had to be 'refreshed' by using drop/create scripts which essentially just dropped it and recreated the exact same view. I do not recall the exact error message that was returned other than it seemed to suggest that it could no longer see the secondary view since it had been changed. Nothing in the primary view was changed in any way, just the secondary.
Some here where I work have suggested off hand that this was a recompile of the primary view because the contents of the secondary changed.
My questions are:
1. Exactly why did this happen and is there a proper name for it when it does?
2. The same problem does not seem to occur when we have stored procedures referencing views in the joins which had just been changed. Why is that?
Thanks for any help on the matter. I greatly appreciate it.
Hello,
to make a report easier I'm developing it using a view of joined views of joined views.
Is there any significant performance penalty as opposed to just having one big select?
Cheers.
Hi There,
Is it possible to make views which takes Data from Multiple Servers?
NOTE: The view is very complex because it uses FOUR Diff. statements
joined together with UNION clause.
One more Q.
If my Query Analizer Displays following on execution of query.
" Internal Query Processor Error: The query processor could not produce a query plan."
What should be my approach to rectify the problem.
Any help would really be appreciated.
zak
I have ViewA that sums up 4 fields from one table. I then have ViewB that uses ViewA to calculate the results. Now I do this with 5 different tables and then link them all to get my final results. Each View has a date range (begin / end) that I need to pass from a Web form.
How should I go about doing this? Should I create a temporary table to hold the begin / end dates to use in the sub Views? Or something else? I am at a lost on how to go about this and need some direction and syntax?
Thanks in advance for your help!!
I have a large list of table names and want to create a database, and a view for each of the tables with openrowset. There are no constrains no keys nothing. Is there a fast way to achieve that?
View 4 Replies View RelatedI am new to SQL, so I appologize if I am doing something wrong which is really basic.
I am receiving a "Incorrect syntax near ';' " when trying to create a view and then perform action based upon the results
Here is my basic code...the error is on the ; following the create view statement:
create view temp2 as select * from history where crc='XL' and processed<1;
insert into history2 (dialid, calldatetime, origcalldate, crc, revenue, projectid, agentid, phonenum)select temp2.dialid, temp2.calldatetime, temp2.calldatetime, 'XL', 0, history2.projectid, temp2.agentid, temp2.phonenum from temp2, history2where temp2.dialid=history2.dialid and temp2.crc='XL' and temp2.processed<1 and temp2.projectid=110;
What am I doing wrong???
Thanks for your help.
Hello,I am relatively new to doing non-trivial SQL queries.I have to get data out of 8 diff views based on a parameter Name.There is a view having name-ssn pairs. All other views have SSN field.For a person there MAY NOT be data in all the views.I have to populate data into diff tables in a Report from differentviews.I would like to know what is the best way to approach it.So far I was trying an Inner join from the Name-ssn vies to all otherviews based on the SSN and test for the name field with the inputparameter.I am thinking there will be problem of Cross join if I dont have datain all views about a person.Or the best way is to write query for each view and have all of them ina stored procedure ?Any help will be appreciatedThanksBofo
View 1 Replies View RelatedHi champs!
Is it possible to make a database View over two different database installations on different machines?
Many thanks
kurlan
I wonder if anyone has any hard fact based pro or contra, especially onperformance, about having views as opposed to tables when the object isbeing accessed for read only by multiple sessions/users/spids. I amparticularly concerned about the multiple instantiations of the view.Relevant thoughts on this are much appreciated.Thanks,Caveman
View 1 Replies View RelatedHi All,
My database's design is set out here. In summary, I'm trying to model a Stock Exchange for a Technical Analysis application written using Visual C++. In order to create the hierachy I'm using a Nested Set Model. I'm now trying to write code to add and delete equities (or, more generically, nodes) to the database using a form presented to the user in my application. I have example SQL code to create the necessary add and delete procedures that calculate the changes to the values in the lft and rgt columns, but these examples focus around a single table, where as my design aggregates rows from multiple tables using UNION ALL:
Code Snippet
CREATE VIEW vw_NSM_DBHierarchy -- Nested Set Model Database Hierarchy
AS
SELECT clmStockExchange, clmLeft, clmRight FROM tblStockExchange_
UNION ALL
SELECT clmMarkets, clmLeft, clmRight FROM tblMarkets_
UNION ALL
SELECT clmSectors, clmLeft, clmRight FROM tblSectors_
UNION ALL
SELECT clmEPIC, clmLeft, clmRight FROM tblEquities_
Essentially, I'm trying to create an updateable view but I receive the error "UNION ALL View is not updatable because a partitioning column was not found". I suspect that my design in wrong or lacks and this problem is highlighting the design flaws so any suggestions would be greatly appreciated.
Hello There,I'm trying to create a view that has calculations dependent oncalculations, where the problem resides is that each time I make acalculation I must create an intermediate view so I can reference aprevious calculation.for example lets say I have my_table that has columns a & b. now I wanta view that has a & b, c = a + b, and d = c + 1.this is grossly simplified, the calculations I actually use are fairlycomplex and copying / pasting them is out of the question.so what I have is my_view_a which makes column c, and my my_view_finalwhich makes column d (however, in my real application I have 5 of theseviews, a/b/c/d/e/)is there anyway I can consolidate all these views into one? I wasthinking of using a stored procedure with temp tables or somethingalong those lines.I just which I can use the aliases that I create for c in d in onestep.any insight would be greatly appreciated.
View 5 Replies View Relatedwhen to use table variable and temp table. i told the interviewer that when rows is less like hundreds or thousand then use table variable else use temp table.After that he asked that what do u mean by less data or thousand rows may be there are multiple columns involved with that less rows and make a huge data set.
View 3 Replies View Related
Hello,
the application will add items into a "bag". That is, the items in one table will refer a record in another table. This will be done in timely manner -- with second or minute delays between adding a new item. There will be up to thouthand of items per bag. The option is to wait until a full bag accumulates and set up all the references at once by using
UPDATE items SET container_ref = bag WHERE id IN [...]
The disadvantage of such all-at-once I see is inability to encapsulate the functionality into a SP -- the problem is to pass a set of IDs. The advantage should be efficiency in terms of total SQL Server load. How mush would it be?
Hi Experts
We are debating what is best:
1. To combine all the company's data in one large database, and use schemas and file groups to create logical and physical distribution on drives and namespaces
or
2. Distribute the data into smaller databases with related data - eg. products and product description in one db, Customers in another and orders and orderlines in a third db.
Just what are the pros and cons?
regards
Jens Chr
System.OverflowException: Value was either too large or too small for an
Int32. Why does this error originate in the following line?"SqlCommand cmd = new SqlCommand("SELECT Count(*) FROM Contacts", conn)........ ..........DataSetContacts.ContactsRow row = ds.Contacts.NewContactsRow();..................row["ContactNumber"] = Convert.ToInt32(txtContactNo.Text);" ContactNumber field is SqlDbType.Int.
HiThis is a question of "what does it cost me".Lets say I have an integer value which would fit into a smallint fieldbut the field is actually defined as int or even larger as bigint.What would that "cost" me ? How would definitions larger than I need forthe values in the field affect me ?Its obvious that the volume of the database would grow but with the sizeof resources etc that we have nowadays disc space isn't a problem likeit used to be and i/o is much faster and many people would tell me "whocares" , or IS it a problem ?How does it affect performance of data retrieves ? Searches ? Updatesand inserts ? How would it affect all db access if tables are pointingat each other with foreign keys ?Thanks !David Greenberg
View 3 Replies View RelatedHI There,
Generally speaking, is it better to use a large or small stripe size for a Raid 5 array (4 drives) ? I would appreciate any specifics also.
Thanks in advance.
Charlie
Hi,
Please could you tell me how big sql tables are when people refer to them as small, medium and large? Preferably in terms of disk space or rows (each row in my table will contain a standard length job advert and 20 additional columns with an average of 8 characters)
Thanks for your help! :-)
Stu
Hi ,
Is there any method by which I can divide the large flat file into certain number of small files keeping the header in each of the sub files?
Regards,
Prash
Hi everyone, I have a problem like this . I have tables Coursegroupcode, which has groupname, codeI have Courses That has Coursename, its code(group code),Term, Course Number Enrollment table which has Foreign keys Term,Course NUmber , SSN I need to get a view like thisI should list all the coursecodes and people enrolled for each course code for selected terms Course Table Primary keys(TERM,COUSE Number)Enrollment Table(Foreign keys) TERM ,COURSE NUMBER, SSNplease help
View 9 Replies View Related Hi!
I need to know if i can build an aspx file on top of an sql view? I
can only see my tables when i connect to the database....
Collette.
Can SQL Views insert to the tables they are created from?I have a database that is not well structured. It has a lot of redundency. What I want to do is create a SQL View that brings in all the data I need and have my application use that new SQL View instead of the data tables. Then I want to be able to insert new information to a SQL View that actualy gets inserted into the tables that the SQL Viewer is created from.Can this be done?Does this make any sense?
View 1 Replies View RelatedI have a query which unions the four select statements.....
the select statements are joined with other tables and views.....
When i execute the query i get ODBC timeout error........
But the strange thing is that if i execute the view individually once and again execute the query it works fine.......and later it justs works fine....
Can anyone tell why is it like that.......
Thanks,
Sajai.
Is there a performance hit running a sp against a view versus a base table. The view just excludes
several of the records based on some criteria, and all the data I will be retreiving is included in
the view. Or should I just stick my criteria in the SP to exclude the data?
Is there a way to imbed "iif"-like logic in a SQL view? "case when" works in regular queries, but apparently is not supported in views...
View 1 Replies View RelatedI have some rather complex views to work with. Do they slow you down? Would it be better to move a view into a stored procedure? Is there any difference between these three solutions?
<B>1.Using views:</b>
Create view X
As
Select Col1, Col2, Col3 from Table1
Go
Create view Y
As
Select Col1, Col2, Col3 from Table2
Go
Create proc Z
As
Select X.Col2, X.Col3, Y.Col2, Y.Col3
From X inner join Y on X.Col1 = X.Col1
GO
<b>2.Using just a stored proc:</b>
Create proc Z
As
Select X.Col2, X.Col3, Y.Col2, Y.Col3
from
(Select Col1, Col2, Col3 from Table1) X inner join
(Select Col1, Col2, Col3 from Table2) Y on X.Col1 = Y.Col1
<b>.Joining tables</b>
Create proc Z
As
Select Table1.Col2, Table1.Col3, Table2.Col1, Table2.Col3
FromTable1 inner join Table2 on Table1.Col1 = Table2.Col1
go
Thank you!
I am struggling with setting up views in SQL Server 7.0 and 2000. What types of views are available.
I have one database with 112 tables and 2308 fields.
Thanks in Advance
I have created a database connected to a GUI using VB 6.0. When editing the views from the front end, do the tables also get updated
Thanks
Hi,
Is there a way to create a view with read only option. i.e the view should not allow the user to perform insert, update or delete action on it.
Please advise,
Thanks,
Sam
Is there any kind of lock on a view in ms sql database?
what happens if one of my users is looking at the view and another one is adding something to the database?
Thanks.