Hello
I have one probably stupid qestion
I want to create procedure that will create user then create database with the same name as user name and the give that user db_owner permision to that data base i created procedure that creat a user and creat a database but i couldn't do last part of it
becous USE statment can't be use in a procedur
Do you have some idea of how to create something like this ?
e.g.
create proc usp
@.login sysname,
@.pwd sysname=''
as
set nocount on
declare @.sql nvarchar(1000)
set @.sql = '--create database
if db_id('+quotename(@.login,char(39)+char(39))+') is null
create database '+quotename(@.login)
print(@.sql)
exec(@.sql)
set @.sql = '--create login
if suser_sid('+quotename(@.login,char(39)+char(39))+') is null
exec sp_addlogin
'+quotename(@.login,char(39)+char(39))+','+quotenam e(@.pwd,char(39)+char(39))+
','+quotename(@.login,char(39)+char(39))
print(@.sql)
exec(@.sql)
set @.sql = '--grantdbaccess
exec '+quotename(@.login)+'..sp_grantdbaccess
'+quotename(@.login,char(39)+char(39))
print(@.sql)
exec(@.sql)
set @.sql = '--add db_owner
exec '+quotename(@.login)+'..sp_addrolemember
''db_owner'','+quotename(@.login,char(39)+char(39))
print(@.sql)
exec(@.sql)
go
"Nikon" <anonymous@.discussions.microsoft.com> wrote in message
news:1B54E87B-2788-4711-B0F2-31D8AEEA085B@.microsoft.com...
> Hello
> I have one probably stupid qestion
> I want to create procedure that will create user then create database with
the same name as user name and the give that user db_owner permision to that
data base i created procedure that creat a user and creat a database but i
couldn't do last part of it becous USE statment can't be use in a procedur
> Do you have some idea of how to create something like this ?
>
|||THX YOU HELPED ME VERY MUCH I now just must analyz it and understend it =)
Showing posts with label helloi. Show all posts
Showing posts with label helloi. Show all posts
Sunday, March 11, 2012
Create Proc
Hello
I have one probably stupid qestion
I want to create procedure that will create user then create database with t
he same name as user name and the give that user db_owner permision to that
data base i created procedure that creat a user and creat a database but i c
ouldn't do last part of it
becous USE statment can't be use in a procedur
Do you have some idea of how to create something like this 'e.g.
create proc usp
@.login sysname,
@.pwd sysname=''
as
set nocount on
declare @.sql nvarchar(1000)
set @.sql = '--create database
if db_id('+quotename(@.login,char(39)+char(3
9))+') is null
create database '+quotename(@.login)
print(@.sql)
exec(@.sql)
set @.sql = '--create login
if suser_sid('+quotename(@.login,char(39)+ch
ar(39))+') is null
exec sp_addlogin
'+quotename(@.login,char(39)+char(39))+',
'+quotename(@.pwd,char(39)+char(39))+
','+quotename(@.login,char(39)+char(39))
print(@.sql)
exec(@.sql)
set @.sql = '--grantdbaccess
exec '+quotename(@.login)+'..sp_grantdbaccess
'+quotename(@.login,char(39)+char(39))
print(@.sql)
exec(@.sql)
set @.sql = '--add db_owner
exec '+quotename(@.login)+'..sp_addrolemember
''db_owner'','+quotename(@.login,char(39)
+char(39))
print(@.sql)
exec(@.sql)
go
"Nikon" <anonymous@.discussions.microsoft.com> wrote in message
news:1B54E87B-2788-4711-B0F2-31D8AEEA085B@.microsoft.com...
> Hello
> I have one probably stupid qestion
> I want to create procedure that will create user then create database with
the same name as user name and the give that user db_owner permision to that
data base i created procedure that creat a user and creat a database but i
couldn't do last part of it becous USE statment can't be use in a procedur
> Do you have some idea of how to create something like this '
>|||THX YOU HELPED ME VERY MUCH I now just must analyz it and understend it =)
I have one probably stupid qestion
I want to create procedure that will create user then create database with t
he same name as user name and the give that user db_owner permision to that
data base i created procedure that creat a user and creat a database but i c
ouldn't do last part of it
becous USE statment can't be use in a procedur
Do you have some idea of how to create something like this 'e.g.
create proc usp
@.login sysname,
@.pwd sysname=''
as
set nocount on
declare @.sql nvarchar(1000)
set @.sql = '--create database
if db_id('+quotename(@.login,char(39)+char(3
9))+') is null
create database '+quotename(@.login)
print(@.sql)
exec(@.sql)
set @.sql = '--create login
if suser_sid('+quotename(@.login,char(39)+ch
ar(39))+') is null
exec sp_addlogin
'+quotename(@.login,char(39)+char(39))+',
'+quotename(@.pwd,char(39)+char(39))+
','+quotename(@.login,char(39)+char(39))
print(@.sql)
exec(@.sql)
set @.sql = '--grantdbaccess
exec '+quotename(@.login)+'..sp_grantdbaccess
'+quotename(@.login,char(39)+char(39))
print(@.sql)
exec(@.sql)
set @.sql = '--add db_owner
exec '+quotename(@.login)+'..sp_addrolemember
''db_owner'','+quotename(@.login,char(39)
+char(39))
print(@.sql)
exec(@.sql)
go
"Nikon" <anonymous@.discussions.microsoft.com> wrote in message
news:1B54E87B-2788-4711-B0F2-31D8AEEA085B@.microsoft.com...
> Hello
> I have one probably stupid qestion
> I want to create procedure that will create user then create database with
the same name as user name and the give that user db_owner permision to that
data base i created procedure that creat a user and creat a database but i
couldn't do last part of it becous USE statment can't be use in a procedur
> Do you have some idea of how to create something like this '
>|||THX YOU HELPED ME VERY MUCH I now just must analyz it and understend it =)
create other index
Hello:
I create a key in one table, the field is uniqueidentifier, but I search
very frequently for one [date] field, and I like to index this field with
datetime datatype to optimize the search, how can I do that?
Best regards,
Owen."Owen" <anibal@.prensa-latina.cu> wrote in message
news:uxQMR9vEGHA.1032@.TK2MSFTNGP11.phx.gbl...
> Hello:
> I create a key in one table, the field is uniqueidentifier, but I search
> very frequently for one [date] field, and I like to index this field with
> datetime datatype to optimize the search, how can I do that?
> Best regards,
> Owen.
>
CREATE INDEX <indexname> ON <TableName> (<column1>, <column2>, ...)
Example:
CREATE INDEX IX_Frogs_BirthDate ON Frogs (BirthDate)
As a side note.. If you are frequently searching on a range of dates using
statements like BETWEEN, then you may find a CLUSTERED index on this date
column to be far more effective. Clustered indexes on GUIDs can be clumsy
at best.
Rick Sawtell
MCT, MCSD, MCDBA|||hi, thanks for answer:
the problem is that I need keep this two index on the same table, the guid
and the dates, but only one can be CLUSTERED, how can optimize this to all
index work faster?
Best regards,
Owen.
"Rick Sawtell" <Quickening@.msn.com> wrote in message
news:eWCHVDwEGHA.644@.TK2MSFTNGP09.phx.gbl...
> "Owen" <anibal@.prensa-latina.cu> wrote in message
> news:uxQMR9vEGHA.1032@.TK2MSFTNGP11.phx.gbl...
with
> CREATE INDEX <indexname> ON <TableName> (<column1>, <column2>, ...)
> Example:
> CREATE INDEX IX_Frogs_BirthDate ON Frogs (BirthDate)
>
> As a side note.. If you are frequently searching on a range of dates
using
> statements like BETWEEN, then you may find a CLUSTERED index on this date
> column to be far more effective. Clustered indexes on GUIDs can be
clumsy
> at best.
> Rick Sawtell
> MCT, MCSD, MCDBA
>
>|||Owen as you say only one index can be clustered, but one of the significant
benefits of a clustered index is for querioes based on a range of values
since all those rows will be found near each other (all else being equal).
Now a GUID is *extremely unlikely* (probably nearly safe to say never)
likely to be used in a query like
WHERE guidcol between 'yuckyguidvalue1' and 'yuckyguidvalue2'
So makeing the CI on the date will have the benefit (if you retrieve rows
based on a date range) of being faster than retrieving the same range when
the supporting index is non-clustered. Hence Rick's suggestion that you
consider making the CI on the date column.
To go much further needs an understanding of the type of queries on the
table, and the approx size of it, and is frequently best checked by running
testst on your configuration.
You may have guessed I fall in to the camp of disliking guids for any sort
of identifiers unless there is an absolute cast-iron reason for needing them
(like a distributed db that has to have surrogate keys generated uniquely,
or complex replication) .
Mike John
"Owen" <anibal@.prensa-latina.cu> wrote in message
news:eNcVeIwEGHA.3064@.TK2MSFTNGP10.phx.gbl...
> hi, thanks for answer:
> the problem is that I need keep this two index on the same table, the guid
> and the dates, but only one can be CLUSTERED, how can optimize this to all
> index work faster?
> Best regards,
> Owen.
>
> "Rick Sawtell" <Quickening@.msn.com> wrote in message
> news:eWCHVDwEGHA.644@.TK2MSFTNGP09.phx.gbl...
> with
> using
> clumsy
>|||Just don't forget that the GUID may be an FK where the "=" searches would
return many rows. In that case depending on how many queries against each
column and what columns you fetch we still may consider using the GUID as
the clustered index.
/ Tobias|||True - apologies - i was falling into an assumption that the guid was going
to be unique!
Mike
"Tobias Thernstrm" <ttnospam@.rbam.se> wrote in message
news:O%23qfmNCFGHA.3632@.TK2MSFTNGP10.phx.gbl...
> Just don't forget that the GUID may be an FK where the "=" searches would
> return many rows. In that case depending on how many queries against each
> column and what columns you fetch we still may consider using the GUID as
> the clustered index.
> / Tobias
>
I create a key in one table, the field is uniqueidentifier, but I search
very frequently for one [date] field, and I like to index this field with
datetime datatype to optimize the search, how can I do that?
Best regards,
Owen."Owen" <anibal@.prensa-latina.cu> wrote in message
news:uxQMR9vEGHA.1032@.TK2MSFTNGP11.phx.gbl...
> Hello:
> I create a key in one table, the field is uniqueidentifier, but I search
> very frequently for one [date] field, and I like to index this field with
> datetime datatype to optimize the search, how can I do that?
> Best regards,
> Owen.
>
CREATE INDEX <indexname> ON <TableName> (<column1>, <column2>, ...)
Example:
CREATE INDEX IX_Frogs_BirthDate ON Frogs (BirthDate)
As a side note.. If you are frequently searching on a range of dates using
statements like BETWEEN, then you may find a CLUSTERED index on this date
column to be far more effective. Clustered indexes on GUIDs can be clumsy
at best.
Rick Sawtell
MCT, MCSD, MCDBA|||hi, thanks for answer:
the problem is that I need keep this two index on the same table, the guid
and the dates, but only one can be CLUSTERED, how can optimize this to all
index work faster?
Best regards,
Owen.
"Rick Sawtell" <Quickening@.msn.com> wrote in message
news:eWCHVDwEGHA.644@.TK2MSFTNGP09.phx.gbl...
> "Owen" <anibal@.prensa-latina.cu> wrote in message
> news:uxQMR9vEGHA.1032@.TK2MSFTNGP11.phx.gbl...
with
> CREATE INDEX <indexname> ON <TableName> (<column1>, <column2>, ...)
> Example:
> CREATE INDEX IX_Frogs_BirthDate ON Frogs (BirthDate)
>
> As a side note.. If you are frequently searching on a range of dates
using
> statements like BETWEEN, then you may find a CLUSTERED index on this date
> column to be far more effective. Clustered indexes on GUIDs can be
clumsy
> at best.
> Rick Sawtell
> MCT, MCSD, MCDBA
>
>|||Owen as you say only one index can be clustered, but one of the significant
benefits of a clustered index is for querioes based on a range of values
since all those rows will be found near each other (all else being equal).
Now a GUID is *extremely unlikely* (probably nearly safe to say never)
likely to be used in a query like
WHERE guidcol between 'yuckyguidvalue1' and 'yuckyguidvalue2'
So makeing the CI on the date will have the benefit (if you retrieve rows
based on a date range) of being faster than retrieving the same range when
the supporting index is non-clustered. Hence Rick's suggestion that you
consider making the CI on the date column.
To go much further needs an understanding of the type of queries on the
table, and the approx size of it, and is frequently best checked by running
testst on your configuration.
You may have guessed I fall in to the camp of disliking guids for any sort
of identifiers unless there is an absolute cast-iron reason for needing them
(like a distributed db that has to have surrogate keys generated uniquely,
or complex replication) .
Mike John
"Owen" <anibal@.prensa-latina.cu> wrote in message
news:eNcVeIwEGHA.3064@.TK2MSFTNGP10.phx.gbl...
> hi, thanks for answer:
> the problem is that I need keep this two index on the same table, the guid
> and the dates, but only one can be CLUSTERED, how can optimize this to all
> index work faster?
> Best regards,
> Owen.
>
> "Rick Sawtell" <Quickening@.msn.com> wrote in message
> news:eWCHVDwEGHA.644@.TK2MSFTNGP09.phx.gbl...
> with
> using
> clumsy
>|||Just don't forget that the GUID may be an FK where the "=" searches would
return many rows. In that case depending on how many queries against each
column and what columns you fetch we still may consider using the GUID as
the clustered index.
/ Tobias|||True - apologies - i was falling into an assumption that the guid was going
to be unique!
Mike
"Tobias Thernstrm" <ttnospam@.rbam.se> wrote in message
news:O%23qfmNCFGHA.3632@.TK2MSFTNGP10.phx.gbl...
> Just don't forget that the GUID may be an FK where the "=" searches would
> return many rows. In that case depending on how many queries against each
> column and what columns you fetch we still may consider using the GUID as
> the clustered index.
> / Tobias
>
Subscribe to:
Posts (Atom)