Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 19th, 2003, 07:08 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generalized Code

Hi there,
Can anyone tell me what is the best approach for writing an application to talk to database when database schema will change in future? At present we have an older version which will get upgraded to a new one and some data columns might change. I want to design a data layer that should be flexible enough to work with changed schema as well. I am thinking stored procedures might be one option? Any other suggestions? Generating dynamic SQL statements? Any other ideas? I am kindda stuck. Thanks for your feedback.

Paul.
 
Old June 19th, 2003, 11:45 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 132
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You mean you're not using stored procs already?!? Really, that's so mySQL :)
Definately go for stored procs! Also check out views, as they make quite good 'defined interfaces' to procs and other applications. Read up on n-tier architectures. Avoid dynamic SQL if you can.

Hope this helps you get started.

There are two secrets to success in this world:
1. Never tell everything you know
 
Old June 19th, 2003, 12:43 PM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ok great thanks! Any suggestions for good books on this. Database is Sql server 2000.
 
Old June 19th, 2003, 07:04 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wrox's professional SQL Server 2000 and M$'s Inside SQL Server 2000.

Chris is right on the layering of code. At the least encapsulate code into functions and procs. Eg for inserting some data: create a function to insert the data, that function calls a proc to insert the data or retreiving data: create function to retrieve data, that function calls proc to retrieve the data. Obviously create other routines to apply your business logic. One real advantage of using function to return your data is that if the underlying tables change, the chages are limited to that function.

Try to use procs for working with data.

regards
David Cameron
 
Old June 20th, 2003, 10:06 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi David,
Thanks for the response. I will check out Inside SQL Server 2000. So maybe i can create dataviews and stored procedures in a seperate database which sort of provide interface for actual data. SO when the database schema (data table ) changes, I will have to change this newly created database which has views and stored procs. I dont think there will be a way to write something generic enough (which i am trying to achieve) which will work with new database(once its in place) and old database schemas WITHOUT someone manually changing some stored procs and views.

Paul.
 
Old June 23rd, 2003, 06:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'd avoid creating a data access database (ie a database just to hold procs and views). You'll take a slight speed hit and it is likely to be confusing as it is more normal to put the views and procs in the database they are accessing. If you are concerned about people accessing things that they shouldn't, block all permissions on tables, so they are forced operate on tables via the procs and views only.

There is no question that if one thing changes (table), others will have to change (procs, accessor code, business logic etc), however if it is well designed code you limit the changes.

Also I'd try to avoid making something too general. This does no work well with databases. Picking a couple of ways you might generalise:

* Proc that returns everything for a table you specify.
Problem is that this goes into dynamic SQL and the proc will be very poorly performing. See:
http://www.algonet.se/~sommar/dynamic_sql.html

* General table to hold anything, ie structure is ID, AttributeName AttributeValue.
The performance on this one is hideous. Also it flys in the face of good normalisation practices.

Anyway, just try to keep your database normal and to avoid swiss army knife procs (ie procs that do everything).

regards
David Cameron
 
Old June 24th, 2003, 06:48 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok Thanks! I will check this out. Thanks for taking the time out to write back.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Generalized Report.aspx balesh.mind ASP.NET 2.0 Professional 1 August 30th, 2007 11:15 AM
Generalized PopUp.aspx balesh.mind ASP.NET 2.0 Professional 1 August 14th, 2007 01:31 PM
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.