Views / Stored Procedures / Updating Records
Jul 23, 2005
This is a general question regarding the use of view and stored
procedures. I'm fairly new to databases and SQL.
I've created a SQL database using an Access Data Project ("ADP") and
I'm satified with the table structure. I've moved on to building some
front ends for our users.
I'm running into situations where I want subreports to be built from
queries [views or stored procedures-I don't know which to use so I use
the term query] that are dependent on the values in other controls.
I've played with stored procedures and I've figured out how to send
criteria to a stored procedure and then dynamically change the record
source of a subreport.
However, I'm running into cases where I can't add records to the
results of a stored procedure. The table I'm running a stored procedure
on has five fields: (1) Primary Key for each record, (2) FundID that's
a primary key in another table, (3) CompanyID that's a primary key in
another table, (4) Attribute 1 of the (Fund/Company) and (5) Attribute
2 of the (Fund/Company).
The stored procedure filters the set of Fund/Companies based on a
FundID from a form. I can update this stored procedure. However, for
users, they would like to see the Fund Name from the table that has
unique FundIDs. As soon as I include that into the stored procedure, I
can no longer add records.
My questions are many:
1. Is there a primer online that discusses the theory behind my
question? Recordsets, updatability, working with recordsets in forms?
2. What are some best practices for developing subreports, combo boxes,
list boxes, etc. where the data is dependent on the values in a control
3. I'm struggling with the best ways to grab objects on a form. If I'm
on the main form I'm comfortable working with the
Me.__object__.__sub-oject routine. However, if I'm in one subform where
I need another subform to change based on the record I'm in, I feel
that my code to get at the subform is very klunky..
forms.main form name.sub form name.form.record source
I don't even know how I figured out the "form" part before record
source. Again, are there some basic rules or guides about navigating
through forms in VBA?
4. Should I be developing front ends in some other environment?
I know it's a lot, but all the advice from the newsgroups seems to
presuppose some knowledge about how ADP, ADO, ODBC..blah blah and I
can't seem to find any documents about ADP and SQL.
View 3 Replies
ADVERTISEMENT
Jul 22, 2007
Good evening:Can anyone give me the low-down on using view from within my stored procedures? I've got some rather complex views that join multiple tables resulting in a staggering SQL query. I then use stored procedures to accept input parameters to determine order by and direction clauses. This results in some rather large "IF ELSE IF ELSE IF..." statements in my SP. Put a complicated SQL query together with lots of IF THEN and it becomes difficult to keep stuff straight in the SP. Therefore, using the view to keep my SQL in one place is an ideal solution. However, and here's the question, does it have a negative impact on speed and/or scalability. We plan to use these SP's within an ASP.NET website that may get a very large amount of traffic. Any advice/help you can give me would be really appreciated. Thanks!
- Future Daddy
View 2 Replies
View Related
Feb 15, 2001
I have been having troubling getting at views and stored proceduers with ADO objects while developing in VB.
I can get a list of the views and stored procedures, but I don't know how to actually get the text values of them... i would like the text so that I can parse/compare them agianst one another...
Any thoughts or help on this?
I would really appreciate the help!
Matt
View 2 Replies
View Related
Feb 16, 2007
Hello,
This maybe a simple question, I'm using reporting services to make a report, question is can I write a stored procedure that queries from a join of two views instead of two tables?
I'm having trouble getting my table data into the reportable state I want it, and I think organising into views might be easier.
Thanks for any help.
View 3 Replies
View Related
Apr 18, 2007
Hi everybody,I am trying to alter a view inside a Stored Procedure and sql server is not allowing me to do so.Can we not have an alter view inside a Stored Procedure?Here is the code: CREATE PROCEDURE dbo.[UPDATE_VIEW_LINEITEMALLOTMENT] -- Add the parameters for the stored procedure here@MAINID int,@BE VARCHAR(8)ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. --SET NOCOUNT ON; ALTER VIEW [Budget_Management_System].[dbo].[LineItem_OCAFund] AS SELECT TOP (100) PERCENT SUM(dbo.ALL_OCAFUND.AMOUNT) AS Expr2, dbo.APP_LINEITEM.LINENUM, dbo.APP_LINEITEM.PC, dbo.APP_LINEITEM.CATEGORY, dbo.APP_LINEITEM.ROWID, dbo.APP_LINEITEM.MAINID FROM dbo.APP_LINEITEM INNER JOIN dbo.ALL_ORG ON dbo.APP_LINEITEM.ROWID = dbo.ALL_ORG.LINEITEMID INNER JOIN dbo.ALL_OCAFUND ON dbo.ALL_ORG.ROWID = dbo.ALL_OCAFUND.ORGID INNER JOIN dbo.APP_AMENDMENT ON dbo.ALL_ORG.AMENDMENTID = dbo.APP_AMENDMENT.ROWID AND dbo.ALL_OCAFUND.AMENDMENTID = dbo.APP_AMENDMENT.ROWID GROUP BY dbo.APP_LINEITEM.LINEORDER, dbo.APP_LINEITEM.BE, dbo.APP_LINEITEM.MAINID, dbo.APP_LINEITEM.LINENUM, dbo.APP_LINEITEM.PC, dbo.APP_LINEITEM.CATEGORY, dbo.APP_LINEITEM.ROWID, dbo.APP_AMENDMENT.AMENDMENTORDER HAVING (dbo.APP_LINEITEM.BE = @BE) AND (dbo.APP_LINEITEM.MAINID = @MAINID) AND (dbo.APP_AMENDMENT.AMENDMENTORDER = 1) ORDER BY dbo.APP_LINEITEM.LINEORDER ENDthanks a lot,Murthy here
View 7 Replies
View Related
Sep 7, 2007
Hi,I was just wondering if it's possible to access views from stored procedures? I know it doesn't make much sense, but would it be possible? If so, can you also give me some code example?Thanks.
View 4 Replies
View Related
Nov 8, 2007
I do all my data access through stored procedures. Is there any benefit in creating views that the stored procedure accesses. At the moment, I tend to just write the select and join within the stored procedure.
View 12 Replies
View Related
Oct 9, 2002
Is there a way to script views and/or stored procedures from Query Analyzer? I am hoping to do this as part of a stored procedure.
Thanks!
View 3 Replies
View Related
Oct 19, 2001
I have two databases named A and B. They are exactly same table structure, but the records are different, and we have near 400 stored procedures and over100 views in the database A. Now my question is that how can I transfer all stored procedures and views from database A to database B?
Thank you very much!
View 2 Replies
View Related
Dec 1, 2005
Hi All,
Novice question. Would someone explain tell me what a view is used for? Also I am confused about the difference between a function and a stored procedure. They both seem like functions to me.
View 7 Replies
View Related
Jul 20, 2005
Please could someone explain to me the differences between a storedprocedure and a view.The reason for this question is I have two almost identical ASP pages.Both get the same results but one uses a stored procedure and one usesa view. If the query returns no results the 'view page' generateserrors and therefore I have to check for BOF and EOF, whereas the'stored procedure page' does not generate errors and instead wouldappear to return a recordset with 0 entries.Thanks in advanceNeil.
View 1 Replies
View Related
Jun 18, 2007
Hi
what is the diffrence between views and stored procedures in sqlserver 2005
thanks in advance.
View 3 Replies
View Related
Sep 25, 2007
Can you create views within a stored procedure?
View 10 Replies
View Related
Mar 13, 2008
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.
View 9 Replies
View Related
Apr 3, 2008
Our DB has a large amount of tables, and whenever we update a field variable (in this case a varchar length) which we did in nearly all of the tables, we then have to go through and update the stored procedures as well. Is there a way to do this automatically, or can this only be done manually.
View 2 Replies
View Related
Nov 8, 2000
Hello Everybody,
I posted this same question couple of times in the news groups but no answers. I have a 2 tables and i am doing a union query using a view. each has 250 rows. The query takes 20 seconds to return the results. no joins or anything. the create view simply looks like this:
create view myview as
select id, name from table1
union
select id,name from table2
Where as if i write a stored procedure like below, it returns the rows in 4 seconds.
create table #mytable
( id int, name varchar(30))
insert into #mytable (id, name) select id, name from table1
insert into #mytable (id, name) select id, name from table2
select id,name from #mytable.
I prefer doing in the view since both returns the same result. I tried running dbcc, update statistics. but no luck. Can anyone please help me in this issue.
Thanks
Ramesh
View 3 Replies
View Related
Oct 17, 2007
I have a multiple table dataset that needs to be returned, with at least 5 joins, some inner, some left outer.
Currently, this is done via a parameterized stored prodedure, which is used fairly frequently. The parameters only affect the where clause, not the joins.
Would it be better to create the view with the joins already done, then pass in the parameters with the stored procedure? Which is better for overall performance? Which is better for quicker response times to the calling asp.net application?
Thanks in advance,
Leah
View 2 Replies
View Related
Jan 27, 2006
The purpose for my questions is accessing these technologies fromapplications. I develop both applications and databases. Working withMicrosoft C#.NET and Microsoft SQL Server 2000 Production and 2005 TestEnvironments.What is the purpose of a view if I can just copy the vode from a viewand put it into a stored procedure?Should I be accessing views from stored procedures?Should I use views to get information? and Stored Procedures forInserts, Updates and Deletes?What are the performance differences between the two?Thank you for any and all information.SBProgrammer
View 28 Replies
View Related
May 9, 2006
Hi,
I would like to use the view of the company data in the following stored procedures
without needing to pass a value into the CompanyID identity column. Is there a way to do this? The following code contains the view, the insert trigger on the view, and the desired stored procedures.
Also, this code is given me problem as well the error message says it cannot convert varchar to int. This code is located in the insert trigger.
INSERT INTO State(StateName)
VALUES(@StateName)
Here is the code of the company view, notice the C.CompanyID it is used in the GetCompany stored procedure.
SELECT C.CompanyID, C.CompanyName, A.Street, A.City, S.StateName, A.ZipCode, A.Country, P.PhoneNumber
FROM Company AS C INNER JOIN
Address AS A ON C.AddressID = A.AddressID INNER JOIN
State AS S ON A.StateID = S.StateID INNER JOIN
Phone AS P ON C.PhoneID = P.PhoneID
Here is code for the insert trigger on the view
CREATE TRIGGER InsertTriggerOnCustomerView
ON ViewOfCompany
INSTEAD OF INSERT
AS
BEGIN
DECLARE @CompanyName VARCHAR(128)
DECLARE @AddressID INT
DECLARE @Street VARCHAR(256)
DECLARE @City VARCHAR(128)
DECLARE @StateID INT
DECLARE @StateName VARCHAR(128)
DECLARE @ZipCode INT
DECLARE @Country VARCHAR(128)
DECLARE @PhoneID INT
DECLARE @PhoneNumber VARCHAR(32)
--DECLARE @CompanyID INT
SELECT
--@CompanyID = CompanyID,
@CompanyName = CompanyName,
@Street = Street,
@City = City,
@StateName = StateName,
@ZipCode = ZipCode,
@Country = Country,
@PhoneNumber = PhoneNumber
FROM INSERTED
INSERT INTO State(StateName)
VALUES(@StateName)
SET @StateID = @@IDENTITY
INSERT INTO Address(Street, City, StateID, Country, ZipCode)
VALUES(@Street, @City, @StateID, @ZipCode, @Country)
SET @AddressID = SCOPE_IDENTITY()
INSERT INTO Phone(PhoneNumber)
VALUES(@PhoneNumber)
SET @PhoneID = SCOPE_IDENTITY()
INSERT INTO Company(CompanyName, AddressID, PhoneID)
VALUES(@CompanyName, @AddressID, @PhoneID)
END
The stored procedures are here.
CREATE PROCEDURE GetCompany
(
@CompanyID INT
)
AS
BEGIN
SELECT CompanyName,Street, City, StateName,
ZipCode, Country, PhoneNumber
FROM
ViewOfCompany
WHERE
CompanyID = @CompanyID
END
GO
CREATE PROCEDURE AddCompany
(
@CompanyName VARCHAR(128),
@Street VARCHAR(256),
@City VARCHAR(128),
@StateName VARCHAR(128),
@ZipCode VARCHAR(128),
@Country VARCHAR(128),
@PhoneNumber VARCHAR(32)
)
AS
BEGIN
INSERT INTO ViewOfCompany
VALUES(@CompanyName, @Street, @City, @StateName,
@ZipCode, @Country, @PhoneNumber)
END
GO
View 3 Replies
View Related
Apr 12, 2007
Is it possible to get SQL Server to automatically update the table/field names in your stored procedures when changing those table/field names in the database?
View 2 Replies
View Related
Mar 22, 2006
Hi,Right, i have a fairly good understanding of SQL. However, i have a fairly basic understanding of SQL Server.I know Storedprocedures are really good and i'm starting to use them. I understand they are good for making inserting, updating very easy.However when you look at a SQL Server database you get various folder, this leaves me a little confused with what they are all used for? whats the difference between these?Thanks in advance!sorry for the basic question, i'll try to challange you next time
View 1 Replies
View Related
Jul 22, 2007
Greetings,
We have recently begun using transactional replication to keep the data in our SQL Servers synchronized in a geographically dispersed environment. We replicate our tables but we have never replicated views, stored procedures, or user functions in our production systems. We are thinking of doing so but wonder if the overhead of running the replication agents doesn't outweigh the benefits of having replication assist with the occassional change to these design elements.
Is anyone on this forum replicating views, sprocs, and user functions? What has your experience been?
Thanks for any ideas that you share.
BCB
View 4 Replies
View Related
Feb 20, 2007
Hi all--I used the following type of script to migrate tables, views and stored procedures from 'dbo' to 'hqmsuser':
alter authorization on dbo.PK_T_PQ_MASTER to HQMSUSER
alter schema HQMSUSER transfer dbo.PK_T_PQ_MASTER
go
This was per recommendations from the BOL to use instead of the 'sp_changeobjectowner' procedure. I returned the following error:
Msg 15346, Level 16, State 1, Line 3
Cannot change owner for an object that is owned by a parent object. Change the owner of the parent object instead.
Msg 15347, Level 16, State 1, Line 4
Cannot transfer an object that is owned by a parent object.
How do I find and change the parent object on this from 'dbo' to a non-dbo schema ownership?
View 1 Replies
View Related
May 21, 2008
Hi Folks,
I am writing a program that transforms a generic MS SQL database to make it compatible with our application. In order to make the transformation, I have to access all the elements of the generic database programmatically.
I know that the Master database contains all this information. Is there a query that allows me to access the "non-system" tables, sps, views, and functions?
For Tables, I need to know the Name(s) of the tables, the column names, the column type, ALLOW Nulls, Primary Key, Identity Seed settings, and Triggers.
For SPs, I need to know the Name(s) and access the SP source code (assuming it's unencrypted).
For Views, I need to know the Name(s) and access the Views Source
For functions, I need to know the Name(s) and access the function source.
I can see various tables in the Master database from management studio, like sys.objects, sys.tables - which look like they have the info I need. However, when I run a query against master like:
select * from sys.objects .. I get an error:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.objects'.
Thank you in advance.
View 13 Replies
View Related
Jul 31, 2007
I have been looking at the project Real reference implementation for doing auditing of data uploads. The tables and store procedures are in place using identical field and variable names. However, when running the package it does not update the relevant log entry with the end time and status.
I have performed the process manually running the stored procedures, providing the values directly and everything works fine.
I can only assume that the LogID variable is not being updated during the run and therefore the onEnd procedure cannot update the relevant log entry.
One side effect is that it does update the record when it€™s the first record entered into the table but not on any other inserts. Clearing the table each time is not an option.
This has become rather frustrating and would appreciate any assistance.
Thanks.
View 1 Replies
View Related
Nov 9, 2007
Hi,
I've a doubt regarding deploying and creating package (MSI and EXE files) for SQL Stored procedures,views,tables,functions,triggers etc.,just like ASP.NET application by publishing and deploying..Is it possible in the same way for sql objects.If so,pls help me how to do it?
Thanks in advance.
View 1 Replies
View Related
Jan 30, 2008
I'm writing a Windows application (Visual Studio 2005, c#) utilizing a local SQLExpress database. It consists of about 10 tables and I've created about 15 Stored Procedures to address various functions... I can run the update Stored Procedures interactively within the designer and the data tables update as designed. However, if I run the update Stored Procedures from within my windows application is where they fail. I get no error messages, if I return a rowcount variable from the Stored Procedure it tells me that one row was updated (SELECT @RtnVal == @@rowcount)... but when I open the subject table in the designer, there is no new data.
My update queries address both insert and update functions, so if it is new row of data, it performs the insert action, otherwise it updates an existing row.
I can query the data using my stored procedures to load default values into my windows form, I can search and find client records to display in the form... I just can't update records. I'm of the opinion that it is a rights issue, but I can't find any resources that address user access accounts with SQLExpress and windows apps. The current connection string for my local database is set for Integrated Security = true; User Instance = true
I've tried two approaches... one utilizes my stored procedure....
bool bSave;
SqlConnection conn = new SqlConnection(KadaDesk.Properties.Settings.Default.dbKadaConnectionString.ToString());
SqlCommand cmd = new SqlCommand("SavAuthTesterData", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@CtrId", SqlDbType.NVarChar, 20).Value = TestCenterID.ToString();
cmd.Parameters.Add("@AT_Id", SqlDbType.NVarChar, 15).Value = GnuAuthTesterId.ToString();
cmd.Parameters.Add("@AT_Name", SqlDbType.NVarChar, 50).Value = GnuAuthTesterName.ToString();
cmd.Parameters.Add("@AT_Pwd", SqlDbType.NVarChar, 15).Value = GnuAuthTesterPwd.ToString();
cmd.Parameters.Add("@Maint", SqlDbType.NChar, 1).Value = GnuAuthTesterStatus.ToString();
cmd.Parameters.Add("@ModBy", SqlDbType.NVarChar, 15).Value = sAuthTester.ToString();
try
{
conn.Open();
cmd.ExecuteNonQuery();
bSave = true;
}
Then I tried a direct insert...
SqlConnection conn = new SqlConnection(KadaDesk.Properties.Settings.Default.dbKadaConnectionString.ToString());
SqlCommand cmd = new SqlCommand();
SqlTransaction myTrans;
conn.Open();
cmd.Connection = conn;
myTrans = conn.BeginTransaction();
cmd.Transaction = myTrans;
string disDte = DateTime.Now.ToShortDateString();
try
{
string sCmdText = "INSERT INTO Tester (CenterId, AuthTesterId, AuthTesterName, AuthTesterPwd, "
+ "CreateDte, Maint, ModBy) "
+ "VALUES ('" + TestCenterID.ToString() + "','"
+ GnuAuthTesterId.ToString() + "','"
+ GnuAuthTesterName.ToString() + "','"
+ GnuAuthTesterPwd.ToString() + "','"
+ disDte.ToString() + "','"
+ GnuAuthTesterStatus.ToString() + "','"
+ sAuthTester.ToString() + "')";
cmd.CommandText = sCmdText;
cmd.ExecuteNonQuery();
myTrans.Commit();
bSave = true;
}
Both fail... which points to the only common point in both approaches, the connection string and user rights... but I can't find any place to address user accounts or configurations for windows apps.
Thanks for whatever help you can offer...
Jim-
View 5 Replies
View Related
Mar 11, 2008
I have created a stored procedure in sql server 2005 which will fetch a particular record based on the value we supply for a column. It is working fine. The same task i need to implement in my web form. I have a textbox in my webform where i will enter the empage which is in the table. Based on the value the record(s) should get displayed in the gridview. How to acheive this. Pls help me with full coding. it is urgent.
Thanx is advance
View 1 Replies
View Related
Mar 18, 2014
I have a situation where deleting old records is blocking updating latest records on highly transactional table and getting timeout errors from application.
In details, I have one table called Tran_table1 in OLTP database. This Tran_table1 is highly transactional table, it will receive data for insert/update continuously
While archiving 2 years old records from Tran_table1 into Tran_table1_archive in batches(using DELETE OUTPUT INTO clause), if there is any UPDATEs on Tran_table1,these updates are getting blocked and result is timeout errors in application.
Is there any SQL Server hints to avoid blocking ..
View 3 Replies
View Related
Oct 3, 2001
When I change a table through the Enterprise Manager, I then have to go and manually refresh all views dependant on that table, even though they don't reference the new column explicitly (they use .*) - just opening the view, typing a space and resaving it works. Obviously this is the dumb way to do it - is there a way to automatically refresh the views?
View 1 Replies
View Related
Dec 15, 2006
hi,is it possible to update views?
if means please tell how?
this is my view:
create view upd_view as
select a.name,a.id,a.salary,b.designation from emp0 a,updview b where a.id=b.id;
select * from upd_view;
NAME ID SALARY DESIGNATION
-------------------- --------- --------- --------------------
Amama 2 3 manager
papa 23 10000 engineer
ammu 24 12345 father
i want to update name where id=2 in the view so please can any one help me to update.
View 4 Replies
View Related
May 18, 2007
Is there any gud topic on "updating tables using Views".Plz let me know
View 3 Replies
View Related
Jul 23, 2005
This from a SQL Server manual:"Complex queries, however, such as those in decision support systems,can reference large numbers of rows in base tables and aggregate largeamounts of information into relatively concise aggregates (such as sumsor averages). SQL Server 2000 supports creating a clustered index on aview that implements such a complexquery. When the CREATE INDEX statement is executed, the result set ofthe view SELECT is stored permanently in the database. Future SQLstatements that reference the view will have substantially betterresponse times. Modifications to the base data are automaticallyreflected in the view."My question arises from the last sentence. At what point are the viewsupdated with the new data? If I am running a transaction that updatessome dependent tables, is there a performance impact while the indexedviews are updated?Jess Askin.
View 3 Replies
View Related