Re: Writing updates from a wide DataTable

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Nigel,

SQL Server will also cache query plans for parameterized queries. The only
issue is, if you keep changing the number of parameters then it is caching
too many i.e. not effectively caching very well. Oracle would be the same.
Also, you don't have to go to 100 parameters just because you have a null,
use a where clause that looks like this Where (emp_name = ? OR ((emp_name IS
NULL) AND (? IS NULL))) .

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------

"Nigel Norris" <nospam@xxxxxxxxxx> wrote in message
news:eqPe$xBlFHA.1440@xxxxxxxxxxxxxxxxxxxxxxx
> Marina, Bill, Sahil,
>
> Thanks for the great comments - very helpful.
>
> In past projects I've used a mix of stored procedures and direct SQL (or
> ADO generated updates). Reading through the various debates on using an SP
> layer as part of the DAL, I've been almost convinced by the 'purist' view
> that all access to the database should be mediated by an SP layer. And
> that's what the Patterns and Practices folks seem to be advocating. But
> it does get a bit messy in cases like this.
>
> Maybe the 'right' answer depends on the architecture. In my case I'm
> looking at 3-tier, and the web service sitting in front of my database is
> an integral part of the access to the database. I think I'm prepared to
> view the DAL in the middle tier as something that will probably need to be
> updated for schema changes, and only use stored procedures if there seems
> to be a particular need for flexibility - typically on complex queries.
>
> If I was doing 2-tier, I think I'd still look at the pure SP layer, and
> find a way of tackling my wide table. One alternative to using dynamic SQL
> in the SP to build a custom update was to group the columns in the table
> and provide and an update procedure for each group. The client would have
> to know enough to invoke the right procedure(s), but the columns do tend
> to naturally fall into groups that are updated together.
>
> I guess I was suprised that this type of problem was not seen as more of
> an issue - all the discusison and samples in the P&P documents seem to
> pick examples where the table only has two or three columns to update.
>
> More comments inline below.
>
> Nigel
>
> "William (Bill) Vaughn" <billvaRemoveThis@xxxxxxxxxx> wrote in message
> news:<#ykGXL6kFHA.2660@xxxxxxxxxxxxxxxxxxxx>...
>> If you roll your own UpdateCommand, you don't have to set columns you
>> don't want to set and you can still use a SP. The UpdateCommand can
>> define all 50 Parameters but pass NULL or your own "flag"(you might want
>> to SET some columns to NULL) that could be used in the SP logic that says
>> not to SET this column.
>>
>
> Most of my columns allow nulls and I can't be sure I won't want to set
> them to null, so I'd really need a flag parameter for each one to say
> whether to use it or not. Now my proc has 100+ parameters :-(
>
> I don't know much T-SQL. For Oracle, I think it would be quite hard work
> in PL/SQL building a completely dynamic update command.
>
>>Creating your own UPDATE statement on the fly is what ADO classic
>>did--based on changed columns (one of the Update Criteria property
>>settings). It's not a bad idea, but moves more schema-dependent logic to
>>the client than I would typically like to do.
>
> Yes - that's one of the things that bothered me. Presumably the classic
> ADO folks feel that this is a backward step. I guess Microsoft wouldn't
> have taken it without them feeling that the classic ADO way was a bad
> idea.
>
> "Sahil Malik [MVP]" <contactmethrumyblog@xxxxxxxxxx> wrote in message
> news:uWn7Cl6kFHA.3448@xxxxxxxxxxxxxxxxxxxxxxx
>
>> And are you planning on doing column-level access restrictions anytime
>> soon?
>
> Nope - but who can plan for what a DBA might do in future :-)
>
>> Are query plans cached with that?
>
> Good point. I can't speak for SQL Server - I know Oracle will cache query
> plans provided you've used parameterized commands. If you've built the
> entire command using literals, then the query plan caching doesn't do you
> much good. Probably not an issue for updates, but definitely an issue for
> dynamically built queries.
>
>


.



Relevant Pages

  • Re: Slow Execution Performance
    ... Restored our SQL Server 2000 database to the empty SQL Server 2005 ... You will need to analyse the query plans for these slow queries to see ...
    (comp.databases.ms-sqlserver)
  • Importance of Max Degree of Parallelism in SQL Server
    ... This setting can be changed at the server level by setting the value to 1, which will prevent parallel execution of all queries fired. ... thejami wrote: ... We have four processors on our SQL Server and want to turn on all four now ... parallelism" configuration option. ...
    (microsoft.public.sqlserver.server)
  • Re: The best elegant solution to override 65k rows limit in a sheet
    ... Access ships with MSDE.. ... >SQL Server Books Online (again-- Access ships with freeware SQL Server ... better ways to achieve their results through queries. ...
    (microsoft.public.excel)
  • Re: Official Status of SQLServer 2005 ADP
    ... solution might be to use ADP. ... With MDB and Linked tables, the only ways of accelerating things are the use ... of Views and the cumbersome use of SQL passthrough queries. ... > SQL Server, and carry on using Access like I aways had. ...
    (microsoft.public.access.adp.sqlserver)
  • Re: SQL Server 2000 and Latching problem
    ... While the way we indexed our tables and the way we wrote the queries etc ... "chances are you are getting latches because you are ... query on the results the query .. ... SQL Server 2000 and Latching problem ...
    (microsoft.public.sqlserver.connect)