473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 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 7675
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 the problem. I get a syntax error " Line 55:...
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 difference of one statement in the WHERE clause. If I...
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 an "ID" column which would be auto-increment...
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 int, title varchar(32) ); INSERT INTO randtest...
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 is a form that will work for a given orderid,...
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 below the call to that stored procedure does not...
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 use ALTOBJ with this thread. I'm not going to get...
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 values by casting them as follows: ...
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 that user are shown as db2 =get authorizations...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.