-- Create the
Contractor role CREATE ROLE Contractor;
GO
--
Allows contractors to query and view the definitions of table in -- the dbo
schema GRANT
SELECT,
VIEW DEFINITIONON SCHEMA::[dbo] to [Contractor];
GO
--
Allows contractors to control Special schema
GRANT
CONTROL ON
SCHEMA::[Special]
to [Contractor];
GO
--
Allows contractors to create tables, views, and stored procedures-- in the
database GRANT
CREATE PROCEDURE TO [Contractor];
GO
After
DBA/Developer create the Contractor role, DBA/Developer should then create
contractor accounts with the Special schema as a default schema and make them a
member of the Contractor role. When a member of the role creates a database
object, it will be created in the user's default schema. The following
Transact-SQL will create the Contractor1 user with a default schema of Special
and assign the user to the Contractor role:
CREATE
LOGIN [Contractor1]
WITH
PASSWORD=N'12345'GO
CREATE
USER [Contractor1]
FOR
LOGIN [Contractor1] WITH
DEFAULT_SCHEMA=[Special]
GO EXEC sp_addrolemember N'Contractor ', N'Contractor1'
--Allow
user to connect to database
GRANT
CONNECT TO [Contractor1]
DBA/Developer
can specify a schema as the user's default schema before the schema has even
been created. DBA/Developer should note that if the user is authenticated via a
Windows group, the user will have no default schema assigned. If such a user
creates an object, SQL Server will create a new schema in which the object is
created. The new schema created will have the same name as the user that
created the object. When a schema is no longer needed, such as when the project
is complete, DBA/Developer can drop it using the DROP SCHEMA statement. To be
dropped, a schema must be empty, or the DROP SCHEMA statement will generate an
error. Therefore, in this scenario, DBA/Developer could first move the objects
from the Special to the dbo schema. DBA/Developer can use the TRANSFER clause
of the ALTER SCHEMA statement to transfer objects from one schema to another.
After transferring all objects to another schema, DBA/Developer could drop the schema.
The following Transact-SQL will move the ContractorTbl table from the Special schema
to the dbo schema and then drop the Special schema:
ALTER SCHEMA dbo
TRANSFER Special.ContractorTbl;
DROP SCHEMA Special;
No comments:
Post a Comment