Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to Create User and Associate DB

Status
Not open for further replies.

PU36

MIS
Mar 16, 2005
202
US
I'm trying to create a script that will create a user account and then associate that user to the DB's for that user.

I have the following to create it but how do you have the script ask for the User name prior to creating the user.

USE [master]
GO
CREATE LOGIN [DOMAIN\USERNAME] FROM WINDOWS WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english]
GO
USE [DB]
GO
CREATE USER [DOMAIN\USERNAME] FOR LOGIN [DOMAIN\USERNAME]
GO
USE [DB]
GO
ALTER USER [DOMAIN\USERNAME] WITH DEFAULT_SCHEMA=[DOMAIN\USERNAME]
GO
USE [DB]
GO
CREATE SCHEMA [DOMAIN\USERNAME] AUTHORIZATION [DOMAIN\USERNAME]
 
T/SQL scripts can not prompt the user for information. The user has to provide all the information prior to running the script.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top