.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Enterprise t-sql Stored Procs against tables -vs- Views

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :Sql Server
I work for a very large enterprise and I am wanting to know what is the best way to design t-sql for the stored proces to be used from an application? Option 1 - Be sure to optimize your Database design so your application will only require at most 6 joins and used stored procs for queries using proper indexs to gain the most performance Option 2 - Create Views and use stored procs against the views My questions:  1. What is the perfromance hit in using views.   My thought process is that views should only be used when you know the data you want to return "hence the name 'VIEW', should not be used as a query".   2. Are stored procs against the schema tables the best for performance. 3. What is the best way to tune and ensure your stored proc is optimal with the correct indexes, so you build a lighting fast query? http://www.mmwebs.com

View Complete Post

More Related Resource Links

Data Truncation issue with Enterprise Library Logging WriteLog stored Proc


Hi ,

I'm using Enterprise Library Logging  feature for logging. The issue i am facing is when the Logging message is too large(more than 65534 chars) ,complete data  is not logged in the Formatted Mesage column which is  of data Type nText .

I am able insert complete data if i try inserting from Sql insert Query from sql management studio. Do i need to add any attributes to data base listener or do i need to change the sp.

 Is there any way to increase the WriteLog stored proc param size in EnterpriseLibrary.Logging config file ? . Please let me know.


Thanks In Advance.

Test Run: Automate Testing of Your Stored Procs


Many Windows®-based applications have a SQL ServerT back-end component that contains stored procedures. Although techniques to automatically test functions in the front-end code are well known, the techniques to write test automation for stored procedures are not.

James McCaffrey

MSDN Magazine September 2004

Sql Scripts - Delete all Tables, Procedures, Views and Functions


In a shared environment you typically don't have access to delete your database, and recreate it for fresh installs of your product. 

I managed to find these scripts which should help you clean out your database.

Use at your own risk.


Delete All Tables

--Delete All Keys


Extended stored procs on 64 bit MSSQL 2008

We need to develop some extended stored procedures for 64-bit SQL Server 2008. We have written the DLL in Visual C++ but when we try to register it with the database, we see the following error: [Microsoft][ODBC SQL Server Driver][SQL Server]Could not load the DLL c:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\Binn\xp_test.dll, or one of the DLLs it references. Reason: 193(failed to retrieve text for this error. Reason: 15105).(42000,17750) Procedure(xp_test) Can anyone please tell me if you have come across such an issue and how it was successfully resolved? 

Can i write stored proc for the two queries, truncating and inserting two different tables?

Hi All, I have two queries below. trying to write stored proc so i can combine these queries so i can use only one execute sql task. both the queries are truncating and inserting records in two different tables. QUERY 1 à   truncate table [PlanFinder].[InvalidAwps] go   INSERT INTO [PlanFinder].[InvalidAwps]     (Ndc, AwpUnitCost)     SELECT DISTINCT P.Ndc Ndc, A.Price AwpUnitCost     FROM         PlanFinder.PlanFinder.HpmsFormulary P         LEFT JOIN (SELECT Ndc, Price FROM MHSQL01D.Drug.FdbPricing.vNdcPrices                     WHERE PriceTypeCode = '01' AND CurrentFlag = 1) A     ON P.Ndc = A.Ndc      WHERE (A.Ndc IS NULL OR A.Price <= 0 OR A.Price IS NULL)     AND p.Ndc IS NOT NULL --------------------------------------------------------- Query 2 à   truncate table [PlanFinder].[MissingNdcs] go   INSERT INTO [PlanFinder].[MissingNdcs]     (Ndc)     SELECT DISTINCT Ndc     FROM         PlanFinder.InvalidAwps       WHERE AwpUnitCost IS NULL  Thanks a

problems running stored procs on AS400 iSeries DB2

Hi, Im working on SSIS packages to populate a SQLServer Data warehouse from an I Series AS400 DB2. Downoading data is no problem, using the ISeries IBMDA400 provider. But I need to upload a couple od tables to the iSeries and then run a stored procedure to copy them into the prodution tables. To do this I had to switch to the iSeries provider IBMDASQL. this runs fine when running in BIDS debug mode but when I save the package on the server and run it from a job, it dails with an invalid password on the connection. I have tried this with, Protection level Server Storage, encrypt with password, and dont save sensitive, using a configuration table, in all cases it works fine running in BIDS, on the dev server, but runing as a SQLSERVE job on the same server it fails. when I saved as Server storage i got the following from the job but it works from BIDS Message Executed as user: Domain\XXXXXXXX. ...lity  Version 9.00.3042.00 for 32-bit  Copyright (C) Microsoft Corp 1984-2005. All rights reserved.    Started:  7:38:53 AM  Error: 2010-09-08 07:38:55.30     Code: 0xC0202009     Source: PJCMTest001 Connection manager "GroupQAC.RunProc"     Description: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.  An OLE DB record is available.&

MS Access and Stored Procedures or Views

Can Microsoft Access access a stored procedure on the SQL Server? If not, is there any way to assign a parameter to a view? I can link to a view in Access, but I cannot link to a procedure. I need to SELECT * from aTable WHERE ID = [@PassidInID]. Any way to do this through Access? The reason for this, is because I am trying to run an existing query (which is very busy - using other queries with queries in them etc.), and I keep getting an ODBC error. I am thinking that if I move the queries to the SQL Server, it may get rid of this error? It's a 2-tier app I have. Tables on the server, forms, queries, and everything else in Access. Thanks in advance - I hope.

Using SQL Views like Tables from DB

Unfortunatrly I've not been able to google what I'm looking for, so either its not a problem for others or there is to much other "noise" so what 'm looking for doesn't show up.Using .net 4, MVC 3 I can pull data from a table in SQL Server as follows:        public ActionResult IndexTelDataset()        {            // Table: Customer             CustomersTableAdapter ta = new CustomersTableAdapter();            NorthwindDataset.CustomersDataTable Customers = new NorthwindDataset.CustomersDataTable();            ta.Fill(Customers);             // Return view              return View(Customers);        }How would I do the same using a vew called vwCustomerDetails? Also on the same topic whats the best way to do a query such as "Select * from Customers".  Thanks!Quentin

Stored Procs tutorial/learning resources?

I've always used some kind of ORM to fetch data,  LinqToSQL or NHibernate so i guess im spoiled - but now i have a prospective job where they primarily use stored procs.  Not my first choice as i'm not all too comfortable with DBs in general - but i like to brush up on stored procs - almost a Stored Procs for Dummies kind of thingWhats a good resource you guys use for this? I just wanna show that i some initiative and more or less hit the ground running when it comes to stored procs - assuming im selected.Thanks!

Does a Maintenance Plan "Rebuild Index" task on Tables + Views rebuild the full text indexes ?


As subject really.

I'm talking about a complete rebuild - not an incremental, or a re-organise.

SQL 2005

The full text indexes are only on individual tables, not Views.

I've asked a similar question before, but sufficiently different, and other is marked as Answered so thought I'd open a new Q : http://social.msdn.microsoft.com/Forums/en/sqltools/thread/5f17f4f1-fba9-436f-aedf-cfbfd89c8db2)


Report using Stored Proc calling multiple Stored Procs


Hi guys,

I am new to SSRS. I have to create a report from a Stored Proc. Thi Stored Proc excepts just one parameter 'ErecNo'. This parameter is passed to fetch the columns from table1. This result set contains OrderID. The OrderId is further passes to 5 SP's in to fetch 5 more result sets. Output of the main stored proc contains 6 result sets.

Now I have to create a report using this SP to show all the Result sets in a Single report. But When I pass the Parameter in SP in SSRS. It ends up showing just one result set with Order ID. 

Can you please guide me how can I show all the result set in a Single report? 



Two results from two different tables by Stored Procedure and put them in variables and send email.


Hi All, first i had like 7-8 steps just to execute stored proc and send email. now i have put everything in one stored proc as follows :

Alter procedure PlanFinder.InsertInvalidRecords

Truncate table [PlanFinder].[InvalidAwps] 
INSERT INTO [PlanFinder].[InvalidAwps](Ndc, AwpUnitCost) 

SELECT DISTINCT P.Ndc Ndc, A.Price AwpUnitCost 
    PlanFinder.PlanFinder.HpmsFormulary P 
    LEFT JOIN (SELECT Ndc, Price FROM MHSQL01D.Drug.FdbPricing.vNdcPrices  
               WHERE PriceTypeCode = '01' AND CurrentFlag = 1) A 
ON P.Ndc = A.Ndc  
WHERE (A.Ndc IS NULL OR A.Price <= 0 OR A.Price IS NULL) 

DELETE FROM PlanFinder.NdcAwp
       Ndc IN
              SELECT Ndc
              FROM  PlanFinder.InvalidAwps                     &nb

Stored Procedures using XQuery to insert XML data into tables


If I have the following XML being passed as a parameter into a stored procedure.


<name>My Bookstore</name><br/>
<location>New York</location><br/>
 <title lang="eng"&g

How to take the scripts of the changed SPs/Views/Temp tables/Functions automatically?



  We have a huge Database with more than 100 tables , more than 150 SPs.We are 10 members and we will be creating/deleting/updating SPs , functions, views, tem tables  everyday. Actually at the end of the day, we have to send the  scripts of latest SPs,functions,views,Temp tables to the server. So far what we are doing is  we manually go to the SQL server Scripts Wizard and selecting one by one all the SPs,functions,TTables and views. Is there any quicker way to take the changed stuffs instead going manually?

update two tables from single grid view using stored procedure PLZ help


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace INV_DN
    public partial class Form1 : Form
        SqlConnection con;
        SqlDataAdapter da1;
        SqlCommand cmd;
        //  SqlCommandBuilder cb;
        DataSet ds;
        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            con = new SqlConnection("User Id=sa;Password=123;database=amar");
            cmd = new SqlCommand("getdata", con);

INSERT the Results of a Stored Procedure with Multiple SELECT Statements into Multiple Tables?

I have a stored procedure (which is overly complex and written by someone else) that I need to take the results of and put them into tables.  The stored procedure uses Dynamic SQL to build and then run 5 SELECT statements based on literally hundreds of variables.  I need to take the results of these SELECT statements and put them into tables in a different database.  Rewriting or re-creating the logic of the stored procedure is NOT AN OPTION as the logic may change over time and maintaining it in multiple places would be nightmarish.  Can anybody help me with this?  I've googled extensively, but have only been able to find examples of using one result set not multiple ones.

Can't SSRS 2008 handle stored procedures which return multiple tables?


I tried it and it only returns the first table.

Any suggestion?

Thank you,


ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend