If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Updated View from Stored Procedure

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-27-10, 05:48
tanu.rajgor tanu.rajgor is offline
Registered User
 
Join Date: Aug 2010
Posts: 3
Question Updated View from Stored Procedure

Hi,
I have created one view which have values of 3 different table in it and now i want to update this view though stored procedure but it's not allowing me to do so it gives below error

"Msg 4405, Level 16, State 1, Procedure UserMaster, Line 16
View or function 'v_UserMaster' is not updatable because the modification affects multiple base tables."


please tell me how can i resolve this error....
Reply With Quote
  #2 (permalink)  
Old 08-27-10, 05:57
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Please can you post the SQL for the view?
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #3 (permalink)  
Old 08-27-10, 06:13
tanu.rajgor tanu.rajgor is offline
Registered User
 
Join Date: Aug 2010
Posts: 3
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE UserMaster

@UserId int,
@EmployeeId int,
@UserTypeId int,
@EmployeeName Varchar(255),
@UserName varchar(50),
@Password Varchar(50),
@ContactNo varchar(50),
@EmailAddress varchar(50),
@Active bit,
@UserType varchar(50)

AS
BEGIN
UPDATE v_UserMaster SET
EmployeeName = @EmployeeName,
EmailAddress = @EmailAddress,
UserName = @UserName,
Password = @Password,
ContactNo = @ContactNo,
UserType = @UserType
WHERE UserId = @UserId And EmployeeId = @EmployeeId

END
GO
Reply With Quote
  #4 (permalink)  
Old 08-27-10, 06:27
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
That's not the view - that is the procedure.
Short of it is exactly what the error says so with the view definition we might be able to sort things out.

I really, really hope that isn't storing the user's password in plain text too.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
  #5 (permalink)  
Old 08-27-10, 06:32
tanu.rajgor tanu.rajgor is offline
Registered User
 
Join Date: Aug 2010
Posts: 3
The View looks like
SELECT dbo.tblUserMaster.UserId, dbo.tblUserMaster.UserName, dbo.tblUserMaster.Active, dbo.tblEmployee.EmployeeId, dbo.tblEmployee.EmployeeName,
dbo.tblEmployee.EmailAddress, dbo.tblEmployee.ContactNo, dbo.tblUserType.UserType, dbo.tblUserType.UserTypeId, dbo.tblUserMaster.Password
FROM dbo.tblUserMaster INNER JOIN
dbo.tblEmployee ON dbo.tblUserMaster.EmployeeId = dbo.tblEmployee.EmployeeId INNER JOIN
dbo.tblUserType ON dbo.tblUserMaster.UserTypeId = dbo.tblUserType.UserTypeId



and it does stores the password in plain text
Reply With Quote
  #6 (permalink)  
Old 08-27-10, 06:41
pootle flump pootle flump is offline
King of Understatement
 
Join Date: Feb 2004
Location: One Flump in One Place
Posts: 14,905
Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE UserMaster

    @UserId int,
    @EmployeeId int,
    @UserTypeId int,
    @EmployeeName Varchar(255),
    @UserName varchar(50),
    @Password Varchar(50),
    @ContactNo varchar(50),
    @EmailAddress varchar(50),
    @Active bit,
    @UserType varchar(50)

AS
BEGIN

    BEGIN TRY
        
        BEGIN TRANSACTION
        
            UPDATE v_UserMaster SET
            EmployeeName = @EmployeeName,
            EmailAddress = @EmailAddress,
            ContactNo = @ContactNo
            WHERE UserId = @UserId And EmployeeId = @EmployeeId
            
            UPDATE v_UserMaster SET
            UserType = @UserType
            WHERE UserId = @UserId And EmployeeId = @EmployeeId
    
            UPDATE v_UserMaster SET
            Password = @Password,
            UserName = @UserName
            WHERE UserId = @UserId And EmployeeId = @EmployeeId
            
        COMMIT TRANSACTION
        
    END TRY
    BEGIN CATCH
        
        IF @@TRANCOUNT > 1
        BEGIN
            ROLLBACK TRANSACTION
        END
        
    END CATCH
    
END
GO
Storing passwords as plain text is about as a bad a practice as you can get.
__________________
Testimonial:
Quote:
pootle flump
ur codings are working excelent.
Reply With Quote
Reply

Tags
multi tables, stored procedure, update view

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On