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 4026066
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:55:27+00:00 2026-05-20T10:55:27+00:00

What is dynamic SQL? I read in a book that when we use dynamic

  • 0

What is dynamic SQL?

I read in a book that when we use dynamic SQL, SQL checks for permissions. But when we do not use it, then there is no check of permissions. Why so?

I made a stored procedure, which updates a table.

create proc steve_SP AS update steveTABLE set eid = 2 where ename = 'henry'

OWNER of steve_SP & steveTABLE is STEVE.

I gave permission to a new user, ‘Bob’, to execute steve_SP, but not any permission on steveTABLE.

Now, when Bob executes the procedure, then it executes successfully.

But, when the code of the procedure is changed (dynamic SQL is used) to code below.

create proc steve_SP AS EXECUTE (update steveTABLE set eid = 2 where ename = 'henry' )

And then, Bob executes the procedure. This time the execution of steve_SP FAILS. Why so?

  • 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-05-20T10:55:27+00:00Added an answer on May 20, 2026 at 10:55 am

    Procedures are a way for you to control access to a table.

    You can deny a user all access paths to a table – except via DML stored procs – so it makes sense that CRUD within procs would work where a normal CRUD wouldn’t work for the user.

    However, when you run dynamic SQL, that is actually run in a separate SPID (process) thus it is as if the user is running the code in the dynamic SQL in a new Query Window.

    Therefore, first scenario:

    create proc steve_SP AS update steveTABLE set eid = 2 where ename = 'henry'
    

    User executes steve_SP – which internally makes the update -> OK

    Second:

    create proc steve_SP AS
    EXECUTE ('update steveTABLE set eid = 2 where ename = ''henry''')
    

    The user has access to steve_SP, so that runs. In there is runs EXECUTE, which spins up and runs this in another process:

    update steveTABLE set eid = 2 where ename = 'henry'
    

    Update directly? -> no. You can use WITH EXECUTE AS options to get around this.

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

Sidebar

Related Questions

How do you build and use dynamic sql in a MySQL stored procedure?
In past I use dynamic sql and datatable to get data from database. Such
So I was thinking about creating a dynamic sql question, meaning that i want
Below is a stored procedure to check if there is a duplicate entry in
I know there have been numerous questions here about inline sql vs stored procedures...
Is there a valid way in SQL Server 2005 to read a row of
I like the flexibility of Dynamic SQL and I like the security + improved
which method do you prefer for creating dynamic sql queries? formating or streaming? Is
I want to ask how other programmers are producing Dynamic SQL strings for execution
SO has plenty of Q&As about how to accomplish various tasks using dynamic SQL,

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.