472,342 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,342 software developers and data experts.

Default Table Owner using CREATE TABLE, INSERT, SELECT & DROP TABLE

For reasons that are not relevant (though I explain them below *), I
want, for all my users whatever privelige level, an SP which creates
and inserts into a temporary table and then another SP which reads and
drops the same temporary table.

My users are not able to create dbo tables (eg dbo.tblTest), but are
permitted to create tables under their own user (eg MyUser.tblTest). I
have found that I can achieve my aim by using code like this . . .
SET @SQL = 'CREATE TABLE ' + @MyUserName + '.' + 'tblTest(tstID
DATETIME)'
EXEC (@SQL)
SET @SQL = 'INSERT INTO ' + @MyUserName + '.' + 'tblTest
(tstID) VALUES(GETDATE())'
EXEC (@SQL)

This becomes exceptionally cumbersome for the complex INSERT & SELECT
code. I'm looking for a simpler way.

Simplified down, I am looking for something like this . . .

CREATE PROCEDURE dbo.TestInsert AS
CREATE TABLE tblTest(tstID DATETIME)
INSERT INTO tblTest(tstID) VALUES(GETDATE())

GO

CREATE PROCEDURE dbo.TestSelect AS
SELECT * FROM tblTest
DROP TABLE tblTest

In the above example, if the SPs are owned by dbo (as above), CREATE
TABLE & DROP TABLE use MyUser.tblTest while INSERT & SELECT use
dbo.tblTest.

If the SPs are owned by the user (eg MyUser.TestInsert), it works
correctly (MyUser.tblTest is used throughout) but I would have to have
a pair of SPs for each user.

* I have MS Access ADP front end linked to a SQL Server database. For
reports with complex datasets, it times out. Therefore it suit my
purposes to create a temporary table first and then to open the report
based on that temporary table.

Nov 21 '06 #1
6 7584
Peter
What is the version are you using? SQL Server 2005 has a great feature
EXECUTE AS for such kind of requirements

"Peter Nurse" <Pt****@yahoo.com.auwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
For reasons that are not relevant (though I explain them below *), I
want, for all my users whatever privelige level, an SP which creates
and inserts into a temporary table and then another SP which reads and
drops the same temporary table.

My users are not able to create dbo tables (eg dbo.tblTest), but are
permitted to create tables under their own user (eg MyUser.tblTest). I
have found that I can achieve my aim by using code like this . . .
SET @SQL = 'CREATE TABLE ' + @MyUserName + '.' + 'tblTest(tstID
DATETIME)'
EXEC (@SQL)
SET @SQL = 'INSERT INTO ' + @MyUserName + '.' + 'tblTest
(tstID) VALUES(GETDATE())'
EXEC (@SQL)

This becomes exceptionally cumbersome for the complex INSERT & SELECT
code. I'm looking for a simpler way.

Simplified down, I am looking for something like this . . .

CREATE PROCEDURE dbo.TestInsert AS
CREATE TABLE tblTest(tstID DATETIME)
INSERT INTO tblTest(tstID) VALUES(GETDATE())

GO

CREATE PROCEDURE dbo.TestSelect AS
SELECT * FROM tblTest
DROP TABLE tblTest

In the above example, if the SPs are owned by dbo (as above), CREATE
TABLE & DROP TABLE use MyUser.tblTest while INSERT & SELECT use
dbo.tblTest.

If the SPs are owned by the user (eg MyUser.TestInsert), it works
correctly (MyUser.tblTest is used throughout) but I would have to have
a pair of SPs for each user.

* I have MS Access ADP front end linked to a SQL Server database. For
reports with complex datasets, it times out. Therefore it suit my
purposes to create a temporary table first and then to open the report
based on that temporary table.

Nov 21 '06 #2

Uri Dimant wrote:
Peter
What is the version are you using? SQL Server 2005 has a great feature
EXECUTE AS for such kind of requirements
SS 2K unfortunately.

Nov 21 '06 #3
Hi
Grant EXECUTE permissions on stored procedure to the specific user


"Uri Dimant" <ur**@iscar.co.ilwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Peter
What is the version are you using? SQL Server 2005 has a great feature
EXECUTE AS for such kind of requirements

"Peter Nurse" <Pt****@yahoo.com.auwrote in message
news:11*********************@e3g2000cwe.googlegrou ps.com...
>For reasons that are not relevant (though I explain them below *), I
want, for all my users whatever privelige level, an SP which creates
and inserts into a temporary table and then another SP which reads and
drops the same temporary table.

My users are not able to create dbo tables (eg dbo.tblTest), but are
permitted to create tables under their own user (eg MyUser.tblTest). I
have found that I can achieve my aim by using code like this . . .
SET @SQL = 'CREATE TABLE ' + @MyUserName + '.' + 'tblTest(tstID
DATETIME)'
EXEC (@SQL)
SET @SQL = 'INSERT INTO ' + @MyUserName + '.' + 'tblTest
(tstID) VALUES(GETDATE())'
EXEC (@SQL)

This becomes exceptionally cumbersome for the complex INSERT & SELECT
code. I'm looking for a simpler way.

Simplified down, I am looking for something like this . . .

CREATE PROCEDURE dbo.TestInsert AS
CREATE TABLE tblTest(tstID DATETIME)
INSERT INTO tblTest(tstID) VALUES(GETDATE())

GO

CREATE PROCEDURE dbo.TestSelect AS
SELECT * FROM tblTest
DROP TABLE tblTest

In the above example, if the SPs are owned by dbo (as above), CREATE
TABLE & DROP TABLE use MyUser.tblTest while INSERT & SELECT use
dbo.tblTest.

If the SPs are owned by the user (eg MyUser.TestInsert), it works
correctly (MyUser.tblTest is used throughout) but I would have to have
a pair of SPs for each user.

* I have MS Access ADP front end linked to a SQL Server database. For
reports with complex datasets, it times out. Therefore it suit my
purposes to create a temporary table first and then to open the report
based on that temporary table.


Nov 21 '06 #4
Uri Dimant wrote:
Hi
Grant EXECUTE permissions on stored procedure to the specific user
Thanks Uri,

Yes, all users already have EXECUTE permission - that's not the
problem. Remember that in the original post, I said . . .

In the above example, if the SPs are owned by dbo (as above),
CREATE
TABLE & DROP TABLE use MyUser.tblTest while INSERT & SELECT use
dbo.tblTest.

.. . . that refers to the behaviour when executed by a non-dbo (shall we
call them underprivileged?) user.

Nov 21 '06 #5
Peter
BOL says
Database Owner (dbo)
The dbo is a user that has implied permissions to perform all activities in
the database. Any member of the sysadmin fixed server role who uses a
database is mapped to the special user inside each database called dbo.
Also, any object created by any member of the sysadmin fixed server role
belongs to dbo automatically.

For example, if user Andrew is a member of the sysadmin fixed server role
and creates a table T1, T1 belongs to dbo and is qualified as dbo.T1, not as
Andrew.T1. Conversely, if Andrew is not a member of the sysadmin fixed
server role but is a member only of the db_owner fixed database role and
creates a table T1, T1 belongs to Andrew and is qualified as Andrew.T1. The
table belongs to Andrew because he did not qualify the table as dbo.T1.

The dbo user cannot be deleted and is always present in every database.

Only objects created by members of the sysadmin fixed server role (or by the
dbo user) belong to dbo. Objects created by any other user who is not also a
member of the sysadmin fixed server role (including members of the db_owner
fixed database role):

a.. Belong to the user creating the object, not dbo.
b.. Are qualified with the name of the user who created the object.


"Peter Nurse" <Pt****@yahoo.com.auwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Uri Dimant wrote:
>Hi
Grant EXECUTE permissions on stored procedure to the specific user

Thanks Uri,

Yes, all users already have EXECUTE permission - that's not the
problem. Remember that in the original post, I said . . .

In the above example, if the SPs are owned by dbo (as above),
CREATE
TABLE & DROP TABLE use MyUser.tblTest while INSERT & SELECT use
dbo.tblTest.

. . . that refers to the behaviour when executed by a non-dbo (shall we
call them underprivileged?) user.

Nov 21 '06 #6
Thanks, Uri.

I think what you're saying (and I'm discovering!) is that I'm stuck
with my (perceived) problem.

A friend has made the best suggestion yet:-

How about using a single table with guid, username or SPID
to provide that separation?

Then it becomes a simple delete/insert to update the data.
As an added bonus having a permanent table means that
you can take advantage of all the good things like indexing and
statistics.

Thanks for your help!

Nov 21 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Karen Sullivan | last post by:
Hi, all. I'm fairly new to SQL, and I have been trying to create a table from a text file. I have been looking at this for days, and can't find...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the...
7
by: Yannick Turgeon | last post by:
Hello all, I'm using SS2K on W2k. I'v got a table say, humm, "Orders" with two fields in the PK: OrderDate and CustomerID. I would like to add...
2
by: Thomas T. Thai | last post by:
I would like to select a random record from a group of records so I'd end up with one random record per group: CREATE TABLE randtest ( catnum...
6
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern...
2
by: claus.hirth | last post by:
I wrote a stored procedure that uses a prepared INSERT INTO statement in order to play with the PREPARE and EXECUTE keywords. In transcript 1...
7
by: Serge Rielau | last post by:
Hi all, Following Ian's passionate postings on problems with ALTOBJ and the alter table wizard in the control center I'll try to explain how to...
2
by: syntego | last post by:
We commonly use triggers to log changes to our main tables to historical log tables. In the trigger, we create a concatenated string of the old...
3
by: Rahul B | last post by:
Hi, I have a user UCLDEV1 which is a part of staff and a group(db2schemagrp1) to which i have not given any permissions. The authorizations of...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.