Powderfinger
2008-04-06 14:46:15 UTC
I have a very simple "contact" database that I am about to Upsize to SQL
Server 2005 from Access 2003. I plan to use the Upsizing wizard that is
included in Access, rather than SSMA unless anyone here has any objections.
I am going to leave it in .MDB rather than ADE.
The database, which i named CNSQL, has virtually one table of any
importance - dbo.tblContact . It has a primary key CID, which is the contact
number and also general contact-type fields, I won't list them all but
here's four: FIRST_NAME, LAST_NAME, ADDRESS, PHONE. The table has a few
hundred thousand records in it.
I need three things:
1) a select query (or whatever) that will return the entire table or all
just one record if a CID is specified.
2) an update query (or whatever) that will update every field in one record
based upon the CID.
3) an update query (or whatever) that will update just two fields field in
one record based upon the CID.
4) a query (or whatever) that will backup the database to a file.
I am going to stick with the Access that
There is just one form (of any importance) in the database, frmCONTACT. The
record source of the form is tblContactLocal , this is a one-record local
table I set up .I created local table when the decision was made to upgrade
to SQL Server 2005. It's been working in Access the last few months quite
well(I know what you're thinking, "Why is he upsizing at all? , that's a
long story)
When the user opens this form it will call query 1, to return the one record
from the server and store it in tblContactLocal. The form then opens with
the data in tblContactLocal. The user edits this data then when he/she
closes/saves it calls either Query 2 or Query 1, depending on whether the
user is a queen or worker bee(I have a VBA routine in the form to determine
this).
I decided to implement my four queries with stored procedures, rather than
pass-thru queries. . I thought that this would be the most eddicient way. I
did a few sample upsizes and everything looks ok, although I've never done
this before and I am scared as heck to put it into operations. Here they are
:
1)Store Procedure1
USE [CNSQL]
GO
/****** Object: StoredProcedure [dbo].[procContactSelect]
returns a sigle record if dblCID is not null, or the entire table if it is.
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[procContactSelect]
@dblCID float = NULL
AS
SET NOCOUNT ON
IF @dblCID IS NULL
SELECT CID, FIRST_NAME, LAST_NAME, ADDRESS, PHONE FROM tblContact
ORDER BY CID
ELSE
SELECT CID, FIRST_NAME, LAST_NAME, ADDRESS, PHONE FROM tblContact
ORDER BY CID
FROM tblContact
WHERE CID = @dblCID
RETURN
2)Stored Procedure 2
USE [CNSQL]
GO
/****** Object: StoredProcedure [dbo].[procContactUpdateAll]
updates every field in the contact table based upon dblCID
Script Date: 04/06/2008 09:29:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[procContactUpdateAll]
@dblCID float = NULL,
@strFIRST_NAME NVARCHAR(50) = NULL,
@strLAST_NAME NVARCHAR(60) = NULL,
@strADDRESS NVARCHAR(100) = NULL,
@strPHONE NVARCHAR(12) = NULL,
AS
/* SET NOCOUNT ON */
BEGIN
IF @dblCID IS NOT NULL
UPDATE tblContact SET PHONE = @strPHONE, FIRST_NAME = @strFIRST_NAME
,LAST_NAME = @strLAST_NAME , ADDRESS = @strADDRESS
WHERE CID = @dblCID
END
RETURN
Do you have any suggestions that would improve my first attempts at this
code? Better error checking and exception handling? Perhaps a reference
guide? How would I write the 4th query, I have not attempted it yet?
Any help would be appreciated.
Thanks
Jack
Server 2005 from Access 2003. I plan to use the Upsizing wizard that is
included in Access, rather than SSMA unless anyone here has any objections.
I am going to leave it in .MDB rather than ADE.
The database, which i named CNSQL, has virtually one table of any
importance - dbo.tblContact . It has a primary key CID, which is the contact
number and also general contact-type fields, I won't list them all but
here's four: FIRST_NAME, LAST_NAME, ADDRESS, PHONE. The table has a few
hundred thousand records in it.
I need three things:
1) a select query (or whatever) that will return the entire table or all
just one record if a CID is specified.
2) an update query (or whatever) that will update every field in one record
based upon the CID.
3) an update query (or whatever) that will update just two fields field in
one record based upon the CID.
4) a query (or whatever) that will backup the database to a file.
I am going to stick with the Access that
There is just one form (of any importance) in the database, frmCONTACT. The
record source of the form is tblContactLocal , this is a one-record local
table I set up .I created local table when the decision was made to upgrade
to SQL Server 2005. It's been working in Access the last few months quite
well(I know what you're thinking, "Why is he upsizing at all? , that's a
long story)
When the user opens this form it will call query 1, to return the one record
from the server and store it in tblContactLocal. The form then opens with
the data in tblContactLocal. The user edits this data then when he/she
closes/saves it calls either Query 2 or Query 1, depending on whether the
user is a queen or worker bee(I have a VBA routine in the form to determine
this).
I decided to implement my four queries with stored procedures, rather than
pass-thru queries. . I thought that this would be the most eddicient way. I
did a few sample upsizes and everything looks ok, although I've never done
this before and I am scared as heck to put it into operations. Here they are
:
1)Store Procedure1
USE [CNSQL]
GO
/****** Object: StoredProcedure [dbo].[procContactSelect]
returns a sigle record if dblCID is not null, or the entire table if it is.
******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[procContactSelect]
@dblCID float = NULL
AS
SET NOCOUNT ON
IF @dblCID IS NULL
SELECT CID, FIRST_NAME, LAST_NAME, ADDRESS, PHONE FROM tblContact
ORDER BY CID
ELSE
SELECT CID, FIRST_NAME, LAST_NAME, ADDRESS, PHONE FROM tblContact
ORDER BY CID
FROM tblContact
WHERE CID = @dblCID
RETURN
2)Stored Procedure 2
USE [CNSQL]
GO
/****** Object: StoredProcedure [dbo].[procContactUpdateAll]
updates every field in the contact table based upon dblCID
Script Date: 04/06/2008 09:29:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[procContactUpdateAll]
@dblCID float = NULL,
@strFIRST_NAME NVARCHAR(50) = NULL,
@strLAST_NAME NVARCHAR(60) = NULL,
@strADDRESS NVARCHAR(100) = NULL,
@strPHONE NVARCHAR(12) = NULL,
AS
/* SET NOCOUNT ON */
BEGIN
IF @dblCID IS NOT NULL
UPDATE tblContact SET PHONE = @strPHONE, FIRST_NAME = @strFIRST_NAME
,LAST_NAME = @strLAST_NAME , ADDRESS = @strADDRESS
WHERE CID = @dblCID
END
RETURN
Do you have any suggestions that would improve my first attempts at this
code? Better error checking and exception handling? Perhaps a reference
guide? How would I write the 4th query, I have not attempted it yet?
Any help would be appreciated.
Thanks
Jack