473,659 Members | 2,985 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.TestInse rt), 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 7705
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.c om.auwrote in message
news:11******** *************@e 3g2000cwe.googl egroups.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.TestInse rt), 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******** ********@TK2MSF TNGP02.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.c om.auwrote in message
news:11******** *************@e 3g2000cwe.googl egroups.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.TestInse rt), 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.c om.auwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.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
5138
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: Incorrect syntax near 'DateUpdated'." Here is the query. Any suggestions would be appreciated, as I am trying to learn and improve. Use ACH go if exists (select * from dbo.sysobjects where id =
10
5616
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 create a single View and specify also in this View the WHERE clause that is common in these stored procedures, I will have the new stored procecures changed to be like:
7
12841
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 (and would be the new PK). But, I would really like to have orders with the oldest OrderDate having the smallest ID number and, for a same OrderDate, I'd to have the smallest CustomerID first. So my question is:
2
2570
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 VALUES (1, 'one.one'); INSERT INTO randtest VALUES (1, 'one.two');
6
2412
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, then an expanded version that will work on all orderids with a specific customerinvoiceid as a parameter. I'm sure appropriate joins will handle it, but I'm not making any headway, everything comes back with multiple tuple selected for update...
2
3847
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 work. Yet transcript 2 shows that the stored procedure does its job, if only the table name is provided directly in the statement text string, instead of as a host variable to a prepared statement like in 'EXECUTE stmt USING tabName, fldValue'. --...
7
6978
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 into the GUI because it is hard to describe in text. First of all what is the purpose of ALTOBJ()? This procedure was created mostly for ISVs who need to do produce change scripts to upgrade application from release to release, but it can also
2
11506
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: CAST(O.MYDATE AS CHAR(30)) When directly updating date fields in the main table, the logged value gets saved in the format YYYY-MM-DD as expected.
3
6669
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 Administrative Authorizations for Current User
0
8335
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8528
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2752
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.