how to script security permissions?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eben

    how to script security permissions?

    I have a very large table that is refreshed periodically. Since it's
    so big, I do a 'drop table', 'create table', 'create index' then a bulk
    load. It's much faster than doing a 'delete from'. I also do a
    'shrinkdb' as part of this process.

    The problem, however, is that the user permissions are also dropped in
    this process. So, how can I script the user permissions? For example,
    how do I give 'MyUser' select access to 'MyTable' in 'MyDB'? Many
    thanks!!

    Eben Yong
    yonglove@yahoo. com

  • BillKi

    #2
    Re: how to script security permissions?

    GRANT SELECT ON MyTable TO MyUser

    Comment

    • Erland Sommarskog

      #3
      Re: how to script security permissions?

      Eben (yonglove@yahoo .com) writes:[color=blue]
      > I have a very large table that is refreshed periodically. Since it's
      > so big, I do a 'drop table', 'create table', 'create index' then a bulk
      > load. It's much faster than doing a 'delete from'. I also do a
      > 'shrinkdb' as part of this process.[/color]

      So why not do a TRUNCATE TABLE instead? This is a minimally logged
      operation, and you maintain indexes, permissions etc.
      [color=blue]
      > The problem, however, is that the user permissions are also dropped in
      > this process. So, how can I script the user permissions? For example,
      > how do I give 'MyUser' select access to 'MyTable' in 'MyDB'? Many
      > thanks!![/color]

      I guess you can do this with DMO, if you want to do this programmaticall y.
      However, I have not used DMO myself.


      --
      Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

      Books Online for SQL Server SP3 at
      SQL Server 2025 redefines what's possible for enterprise data. With developer-first features and integration with analytics and AI models, SQL Server 2025 accelerates AI innovation using the data you already have.

      Comment

      • Damien

        #4
        Re: how to script security permissions?

        Erland Sommarskog wrote:[color=blue]
        > Eben (yonglove@yahoo .com) writes:[color=green]
        > > I have a very large table that is refreshed periodically. Since it's
        > > so big, I do a 'drop table', 'create table', 'create index' then a bulk
        > > load. It's much faster than doing a 'delete from'. I also do a
        > > 'shrinkdb' as part of this process.[/color]
        >
        > So why not do a TRUNCATE TABLE instead? This is a minimally logged
        > operation, and you maintain indexes, permissions etc.
        >[/color]
        Although keeping indexes is sometimes a good thing, it's also sometimes
        beneficial to drop all indexes before the truncate and only add them
        back when all the data loading is complete.

        Of course, it depends on how the data loading is being managed (in my
        case, I happen to be loading 3 1/2 million records from a non-R DBMS,
        and having to do it one row at a time - I'd rather not have the indexes
        rebuilt for every insert)

        Damien

        Comment

        • Eben

          #5
          Re: how to script security permissions?

          Thank you, everyone. I did not know about the TRUNCATE TABLE option.
          But accomplishing this objective using DROP TABLE, CREATE TABLE, and so
          on, has required that I learn many other SQL Server methods, so it's
          good for me. I spent more time developing the solution but SQL Server
          doesn't care one way or the other and both methods still get the job
          done in the same amount of time. So, once again, thanks everyone for
          your input!

          Comment

          Working...