473,379 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Best methods to INSERT and UPDATE?

Max
I'm looking for best methods in terms of performance and simplicity to do an
INSERT and UPDATE. Using Microsoft's Application Blocks and SQL Server
stored procedures, this is simple:

Insert:
iNewCustomerID = Convert.ToInt32(SqlHelper.ExecuteScalar(strConn, _
"myStoredProc", _
param1, _
param2, _
param3
.....))

Update:
Same idea, but use SqlHelper.ExecuteNonQuery

THE PROBLEM:
When I insert large tables like a "customers" table that has 50+ fields, now
my stored procedure becomes VERY large and harder to maintain.

Does anyone have any tips on making this easier? My stored proc just seems
way out of hand now (see below). Is there a way I can at least trim it
down?

Thanks!

Max

------- working stored proc that returns the new id --------------
CREATE PROCEDURE InsertCustomers
(
@discountid int,
@email varchar,
@password varchar,
@bill_company varchar,
@bill_firstname varchar,
@bill_lastname varchar,
@bill_add1 varchar,
@bill_add2 varchar,
@bill_city varchar,
@bill_state varchar,
@bill_postal varchar,
@bill_prov varchar,
@bill_country varchar,
@bill_phone varchar,
@bill_fax varchar,
@ship_company varchar,
@ship_firstname varchar,
@ship_lastname varchar,
@ship_add1 varchar,
@ship_add2 varchar,
@ship_city varchar,
@ship_state varchar,
@ship_postal varchar,
@ship_prov varchar,
@ship_country varchar,
@ship_phone varchar,
@ship_fax varchar,
@maillist bit,
@hearaboutus varchar,
@comment varchar,
@created datetime,
@lastlogin datetime,
@logincount int,
@cc_name varchar,
@cc_number varchar,
@cc_expires_month varchar,
@cc_expires_year varchar,
@cc_cvn varchar,
@ip varchar,
@active bit,
@hearaboutus_other varchar,
@check_number varchar,
@browser_type varchar,
@entry_person varchar
)
AS

INSERT INTO customers
(
discountid,
email,
[password],
bill_company,
bill_firstname,
bill_lastname,
bill_add1,
bill_add2,
bill_city,
bill_state,
bill_postal,
bill_prov,
bill_country,
bill_phone,
bill_fax,
ship_company,
ship_firstname,
ship_lastname,
ship_add1,
ship_add2,
ship_city,
ship_state,
ship_postal,
ship_prov,
ship_country,
ship_phone,
ship_fax,
maillist,
hearaboutus,
comment,
created,
lastlogin,
logincount,
cc_name,
cc_number,
cc_expires_month,
cc_expires_year,
cc_cvn,
ip,
active,
hearaboutus_other,
check_number,
browser_type,
entry_person
)
VALUES
(
@discountid,
@email,
@password,
@bill_company,
@bill_firstname,
@bill_lastname,
@bill_add1,
@bill_add2,
@bill_city,
@bill_state,
@bill_postal,
@bill_prov,
@bill_country,
@bill_phone,
@bill_fax,
@ship_company,
@ship_firstname,
@ship_lastname,
@ship_add1,
@ship_add2,
@ship_city,
@ship_state,
@ship_postal,
@ship_prov,
@ship_country,
@ship_phone,
@ship_fax,
@maillist,
@hearaboutus,
@comment,
@created,
@lastlogin,
@logincount,
@cc_name,
@cc_number,
@cc_expires_month,
@cc_expires_year,
@cc_cvn,
@ip,
@active,
@hearaboutus_other,
@check_number,
@browser_type,
@entry_person
)
SELECT CAST(@@IDENTITY AS INTEGER)
GO
Nov 18 '05 #1
1 1158
Nope! unless you can trim out fields that aren't going to be
updated/inserted ever. Here's some things I've found that make this a
little easier.

The best way I've found to manage big statements like you have is to use
unix utilities like gawk and sed to automatically generate some of this
stuff, for a certain input text file. Like for example in an input file, I
have fieldnames, fieldtypes, lengths, etc (which by the way you can get out
of a sql query - which I pasted below), then I have awk/sed scripts that run
off this file to create everything I need to access the table. I've even
gone as far as automatically creating sql parameters for insertion into
code. This is very powerful to be able to do this, but you won't figure it
out in 2 minutes, it takes some time to realize what you can do with these
tools. Also too, you don't have to use these unix utilities, you can create
a program in the language you are comfortable with to generate this stuff.

Hope this helps too, it took me awhile to figure this one out, but this is
some sql to get this information out of sql server.

select
c.table_name as TableName,
c.column_name as ColumnName,
p.value as ColumnDescription,
c.data_type as DataType,
c.character_maximum_length as DataTypeSize
from information_schema.columns as c
inner join dbo.sysusers as u on u.name = c.table_schema
inner join dbo.sysobjects as o on o.name = c.table_name and o.uid = u.uid
left outer join dbo.sysproperties as p on p.id = o.id and p.smallid =
c.ordinal_position
Where c.table_name = 'myTableName'

--Michael

"Max" <ma*****@portvista.com> wrote in message
news:F2********************@twister.tampabay.rr.co m...
I'm looking for best methods in terms of performance and simplicity to do an INSERT and UPDATE. Using Microsoft's Application Blocks and SQL Server
stored procedures, this is simple:

Insert:
iNewCustomerID = Convert.ToInt32(SqlHelper.ExecuteScalar(strConn, _
"myStoredProc", _
param1, _
param2, _
param3
....))

Update:
Same idea, but use SqlHelper.ExecuteNonQuery

THE PROBLEM:
When I insert large tables like a "customers" table that has 50+ fields, now my stored procedure becomes VERY large and harder to maintain.

Does anyone have any tips on making this easier? My stored proc just seems
way out of hand now (see below). Is there a way I can at least trim it
down?

Thanks!

Max

------- working stored proc that returns the new id --------------
CREATE PROCEDURE InsertCustomers
(
@discountid int,
@email varchar,
@password varchar,
@bill_company varchar,
@bill_firstname varchar,
@bill_lastname varchar,
@bill_add1 varchar,
@bill_add2 varchar,
@bill_city varchar,
@bill_state varchar,
@bill_postal varchar,
@bill_prov varchar,
@bill_country varchar,
@bill_phone varchar,
@bill_fax varchar,
@ship_company varchar,
@ship_firstname varchar,
@ship_lastname varchar,
@ship_add1 varchar,
@ship_add2 varchar,
@ship_city varchar,
@ship_state varchar,
@ship_postal varchar,
@ship_prov varchar,
@ship_country varchar,
@ship_phone varchar,
@ship_fax varchar,
@maillist bit,
@hearaboutus varchar,
@comment varchar,
@created datetime,
@lastlogin datetime,
@logincount int,
@cc_name varchar,
@cc_number varchar,
@cc_expires_month varchar,
@cc_expires_year varchar,
@cc_cvn varchar,
@ip varchar,
@active bit,
@hearaboutus_other varchar,
@check_number varchar,
@browser_type varchar,
@entry_person varchar
)
AS

INSERT INTO customers
(
discountid,
email,
[password],
bill_company,
bill_firstname,
bill_lastname,
bill_add1,
bill_add2,
bill_city,
bill_state,
bill_postal,
bill_prov,
bill_country,
bill_phone,
bill_fax,
ship_company,
ship_firstname,
ship_lastname,
ship_add1,
ship_add2,
ship_city,
ship_state,
ship_postal,
ship_prov,
ship_country,
ship_phone,
ship_fax,
maillist,
hearaboutus,
comment,
created,
lastlogin,
logincount,
cc_name,
cc_number,
cc_expires_month,
cc_expires_year,
cc_cvn,
ip,
active,
hearaboutus_other,
check_number,
browser_type,
entry_person
)
VALUES
(
@discountid,
@email,
@password,
@bill_company,
@bill_firstname,
@bill_lastname,
@bill_add1,
@bill_add2,
@bill_city,
@bill_state,
@bill_postal,
@bill_prov,
@bill_country,
@bill_phone,
@bill_fax,
@ship_company,
@ship_firstname,
@ship_lastname,
@ship_add1,
@ship_add2,
@ship_city,
@ship_state,
@ship_postal,
@ship_prov,
@ship_country,
@ship_phone,
@ship_fax,
@maillist,
@hearaboutus,
@comment,
@created,
@lastlogin,
@logincount,
@cc_name,
@cc_number,
@cc_expires_month,
@cc_expires_year,
@cc_cvn,
@ip,
@active,
@hearaboutus_other,
@check_number,
@browser_type,
@entry_person
)
SELECT CAST(@@IDENTITY AS INTEGER)
GO

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: a-ok | last post by:
Hi, My client has a product database od around 20000 items. And it is updated every few days when he gets a catalog from the supplier. It's supposed to work like this: if there already is a...
16
by: D Witherspoon | last post by:
I am developing a Windows Forms application in VB.NET that will use .NET remoting to access the data tier classes. A very simple way I have come up with is by creating typed (.xsd) datasets. For...
16
by: LP | last post by:
Hi, Every morning a .NET application downloads a file with cumulative data which needs to be appended to SQL Server table. This program needs to identify records that have not been previously...
9
by: Alfred Taylor | last post by:
I'm testing the waters of n-tier development and I ran into a scenario that I'm not sure what the best solution would be. I have a Company object which contains a collection of contacts retrieved...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
6
by: Nate | last post by:
I am in a slight predicament trying to determine the most efficient and effective way to connect/disconnect from a database within a business object (c# dll). I'm also keeping in mind the concept...
2
by: Fred Flintstone | last post by:
What's the difference between these two methods? 1 - Parameterrized SQL queries: Dim CommandObject As New Data.SqlClient.SqlCommand With CommandObject .Connection = myConnection...
7
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
4
by: trullock | last post by:
Hi, Can anyone suggest the best way to go about the following... I'm tracking clicks (mouse down x,y coordinates) on a web page by using some javascript to create an XHR which sends the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.