Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Re-Associating a Server Login to a Database User - SQL Server

RSS
Modified on Tue, Apr 19, 2016, 7:58 AM by Administrator Categorized as SQL Server

Overview

When copying a database from one instance of SQL Server, database-level User objects are copied with the database. However, server-level Logins are not. This article gives a sample script to re-associate an existing server Login to a database User.

Script

USE [MyDatabase]
GO
ALTER USER [MyUser] with LOGIN = [MyLogin]
GO
ALTER USER [MyUser] WITH DEFAULT_SCHEMA=[dbo]
GO
EXEC sp_addrolemember N'db_datareader', N'MyUser'
GO
EXEC sp_addrolemember N'db_datawriter', N'MyUser'
GO
grant execute on schema::dbo to MyUser

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2018, Patrick Jasinski.