Showing posts with label assign. Show all posts
Showing posts with label assign. Show all posts

Tuesday, February 14, 2012

Creating databases under MS SQL 2005 Server (SP-2): dbo user role

Good Day,

I am having a problem with creating databases in MS SQL 2005 Server. When I attempt to assign an User Mapping for my SQL user account to the newly created database, the "dbo" user and schema is already assigned. When I try to drop this user in favor of my own, I receive an error message: Cannot alter the user "dbo" (Microsoft SQL Server, Error: 15150). I am connected to my database engine through the "sa" account.

Regards,

Keith

Hi Keith,

The login that creates the database is mapped to a special user called dbo. The dbo is the owner of the database and can not be dropped. The dbo schema is associated with the dbo user so it also can not be dropped.

The sa account will represent itself as dbo in all databases.

to check for yourself: select user_name() when logged in as sa.

Hope this helps,

-Steven Gott

SDE/T

SQL Server

|||

I have a database that must have a unique schema and user account assigned. I want to exchange the default "dbo" user with my own.

Regards,

Keith

|||

Create a new schema and assign the schema owner as whatever user you want to use:

CREATE SCHEMA YourSchemaName AUTHORIZATION YourUserName

If there are already objects in the dbo schema that you need to be in YourSchema, you change the schema with:

ALTER SCHEMA YourSchemaName TRANSFER dbo.ObjectNameToTransfer

You can then assign users the default schema of YourSchemaName. You can change the default schema for exsiting users with:

ALTER USER YourUserName WITH DEFAULT_SCHEMA = YourSchemaName

-Sue

|||

Here is the error that I receive when trying to create a new schema for my database:

Msg 15151, Level 16, State 1, Line 1
Cannot find the user 'cqadmin', because it does not exist or you do not have permission.
Msg 2759, Level 16, State 0, Line 1
CREATE SCHEMA failed due to previous errors.

My user, "cqadmin" has public access of the database in question.

creating databases on the fly

hello,

i am trying to create a database by using a store procedure. This stored procedure takes two input parameters. i want to assign these parameters to the 'Filename' attributes when i'm creating the database both for the .mdf and .ldf files. However i keep getting an error.

These work ---
FILENAME ='c:\program files\microsoft sql server\mssql$sardonyxinstance\data\Sardonyxrioctes tdblog.mdf',

FILENAME ='c:\program files\microsoft sql server\mssql$sardonyxinstance\data\Sardonyxrioctes tdblog.ldf',

These do'nt work---
FILENAME = @.Databasepath,
FILENAME = @.Databaselogpath,

Here is my code:
------------------------------------------------------------------------
CREATE PROCEDURE rico_dbasescript
@.Databasepath varchar(100) = 'c:\program files\microsoft sql server\mssql$sardonyxinstance\data\Sardonyxrioctes tdb.mdf' , @.Databaselogpath varchar(100)= 'c:\program files\microsoft sql server\mssql$sardonyxinstance\data\Sardonyxrioctes tdblog.ldf'
AS
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'Sardonyxrioctestdb')
DROP DATABASE [Sardonyxrioctestdb]

CREATE DATABASE Sardonyxrioctestdb
ON
( NAME = 'Sardonyxrioctestdb_dat',
FILENAME = @.Databasepath,
--FILENAME ='c:\program files\microsoft sql server\mssql$sardonyxinstance\data\Sardonyxrioctes tdb.mdf',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
( NAME = 'Sardonyxrioctestdb_log',
FILENAME = @.Databaselogpath,
--FILENAME ='c:\program files\microsoft sql server\mssql$sardonyxinstance\data\Sardonyxrioctes tdblog.ldf',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB )
GO

I am still researching my problem but i would appreciate any help. Thanks guys.

JamaicanGuy
**I am a newbie .net developer.
Jah Bless!!!!!!!!!!!!Use dynamic sql:
CREATE PROCEDURE rico_dbasescript
@.Databasepath varchar(100) = 'c:\program files\microsoft sql server\mssql$sardonyxinstance\data\Sardonyxrioctes tdb.mdf' , @.Databaselogpath varchar(100)= 'c:\program files\microsoft sql server\mssql$sardonyxinstance\data\Sardonyxrioctes tdblog.ldf'
AS
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'Sardonyxrioctestdb')
DROP DATABASE [Sardonyxrioctestdb]

declare @.SQLString varchar(8000)

set @.SQLString = 'CREATE DATABASE Sardonyxrioctestdb ON
(NAME = ''Sardonyxrioctestdb_dat'',
FILENAME = ' + @.Databasepath + ',
SIZE = 10,
MAXSIZE = 50,
FILEGROWTH = 5 )
LOG ON
(NAME = ''Sardonyxrioctestdb_log'',
FILENAME = ' + @.Databaselogpath + ',
SIZE = 5MB,
MAXSIZE = 25MB,
FILEGROWTH = 5MB )'

execute (@.SQLString)
GO