Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9075449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:51:47+00:00 2026-06-16T18:51:47+00:00

I have created a stored procedure in which I have used a table object

  • 0

I have created a stored procedure in which I have used a table object and inserted some column in it. Below is the procedure:

CREATE Procedure [dbo].[usp_Security] (@CredentialsList dbo.Type_UserCredentialsList ReadOnly) As        
Begin        
  Declare        
    @Result Table        
(  

   IdentityColumn Int NOT NULL Identity (1, 1) PRIMARY KEY,    
   UserCredentials  nVarChar(4000),        
   UserName         nVarChar(100),        
   UserRole         nVarChar(200),
   RoleID           Int,    
   Supervisor       Char(3),        
   AcctMaintDecn    Char(3),        
   EditPendInfo     Char(3),        
   ReqInstID        Char(3)
)

Insert Into @Result     
 Select Distinct UserCredentials, 'No', D.RoleName, D.RoleID,'No', 'No', 'No' From @CredentialsList A    
 Join SecurityRepository.dbo.SecurityUsers B On CharIndex(B.DomainAccount, A.UserCredentials) > 0        
 Join SecurityRepository.dbo.SecurityUserRoles C On C.UserID = B.UserID        
 Join SecurityRepository.dbo.SecurityRoles D On D.RoleID = C.RoleID      
 Where D.RoleName Like 'AOT.%' And B.IsActive = 1 And D.IsActive = 1  

Update A        
 Set A.UserName = B.UserName      
 From @Result A        
 Join @CredentialsList B On A.UserCredentials = B.UserCredentials      

-- "Supervisor" Column        
Update A        
Set A.Supervisor = 'Yes'        
From @Result A        
Join SecurityRepository.dbo.SecurityUsers B On CharIndex(B.DomainAccount, A.UserCredentials) > 0        
Join SecurityRepository.dbo.SecurityUserRoles C On C.UserID = B.UserID        
Join SecurityRepository.dbo.SecurityRoles D On D.RoleID = C.RoleID        
Where D.RoleName In ('AOT.Manager', 'AOT.Deps Ops Admin', 'AOT.Fraud Manager', 'AOT.Fulfillment Manager') 
     And B.IsActive = 1 And D.IsActive = 1

-- Return Result        
Select * From @Result Order By UserName, UserRole    
End

In the above procedure, I have made the use of Table object and then created a clustered index on that table object.

However, if I create a temporary table and then process the above info in the SP, will it be faster than using table object instead of temporary table. I tried creating a seperate Clustered index on a column in a table object, but it does not allow me to create it as we cannot create an index on a table object.

I wanted to make use of temporary table in the above stored procedure, but will it reduce the cost as compared to the use of table object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:51:49+00:00Added an answer on June 16, 2026 at 6:51 pm

    It depends! – as always there are a lot of factors that come into play here.

    A table variable tends to work best for small numbers of rows – e.g. 10, 20 rows – since it never has statistics, cannot have indices on it, and the SQL Server query optimizer will always assume it has just a single row of data. If you have too many rows in a table variable, this will badly skew the execution plan being determined.

    Furthermore, the table variable doesn’t participate in transaction handling, which can be a good or a bad thing – so if you insert 10 rows into a table variable inside a transaction and then roll back that transaction – those rows are still in your table variable. Just be aware of that!

    The temporary table works best if you intend to have rather many rows, if you might even need to index something.

    Temporary tables also behave just like regular tables in transactional processing, e.g. a transaction will affect those temporary tables.

    But again: the real way to find out is to try it and measure it – and try again and measure again.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below is stored procedure I have written which used nested cursor. create or replace
I have just created a report in Report Manager using a Stored Procedure which
I have a stored procedure which returns a ref cursor as follows: CREATE OR
I have a stored procedure in which i want to create a user defined
I have a following stored procedure in which I have used a cursor. Depending
I have a temporary table in the stored procedure which is causing the time
I have a dynamic SQL statement I've created in a stored procedure. I need
I have a stored procedure :- CREATE procedure St_Proc_GetTimeEntryID @userID int, @timeEntryID int output
I have following stored procedure: CREATE PROCEDURE testProc(IN p_idProject INTEGER) BEGIN DECLARE nowTime DATETIME;
I have this stored procedure: CREATE OR REPLACE PROCEDURE LIQUIDACION_OBTENER ( p_Cuenta IN NUMBER,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.