database creation with user name and password

how can i write query that will create a database. Include the creation of a user named user1 with a password of pword1
hnakumAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MuffyBunnyCommented:
Obviously you'll want to script some tables and stuff to go with it, but here's a script that creates a login on the SQL server, then creates a blank database and assigns that login to your newly created database as a user:

USE [master]
GO

CREATE LOGIN [user1] WITH PASSWORD=N'pword1'
GO

CREATE DATABASE [whatever] ON  PRIMARY 
( NAME = N'whatever', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.IT380LOGI\MSSQL\DATA\whatever.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'whatever_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10.IT380LOGI\MSSQL\Log\whatever_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO

ALTER DATABASE [whatever] SET COMPATIBILITY_LEVEL = 100
GO

IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [whatever].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO

ALTER DATABASE [whatever] SET ANSI_NULL_DEFAULT OFF 
GO

ALTER DATABASE [whatever] SET ANSI_NULLS OFF 
GO

ALTER DATABASE [whatever] SET ANSI_PADDING OFF 
GO

ALTER DATABASE [whatever] SET ANSI_WARNINGS OFF 
GO

ALTER DATABASE [whatever] SET ARITHABORT OFF 
GO

ALTER DATABASE [whatever] SET AUTO_CLOSE OFF 
GO

ALTER DATABASE [whatever] SET AUTO_CREATE_STATISTICS ON 
GO

ALTER DATABASE [whatever] SET AUTO_SHRINK OFF 
GO

ALTER DATABASE [whatever] SET AUTO_UPDATE_STATISTICS ON 
GO

ALTER DATABASE [whatever] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO

ALTER DATABASE [whatever] SET CURSOR_DEFAULT  GLOBAL 
GO

ALTER DATABASE [whatever] SET CONCAT_NULL_YIELDS_NULL OFF 
GO

ALTER DATABASE [whatever] SET NUMERIC_ROUNDABORT OFF 
GO

ALTER DATABASE [whatever] SET QUOTED_IDENTIFIER OFF 
GO

ALTER DATABASE [whatever] SET RECURSIVE_TRIGGERS OFF 
GO

ALTER DATABASE [whatever] SET  DISABLE_BROKER 
GO

ALTER DATABASE [whatever] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO

ALTER DATABASE [whatever] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO

ALTER DATABASE [whatever] SET TRUSTWORTHY OFF 
GO

ALTER DATABASE [whatever] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO

ALTER DATABASE [whatever] SET PARAMETERIZATION SIMPLE 
GO

ALTER DATABASE [whatever] SET READ_COMMITTED_SNAPSHOT OFF 
GO

ALTER DATABASE [whatever] SET HONOR_BROKER_PRIORITY OFF 
GO

ALTER DATABASE [whatever] SET  READ_WRITE 
GO

ALTER DATABASE [whatever] SET RECOVERY FULL 
GO

ALTER DATABASE [whatever] SET  MULTI_USER 
GO

ALTER DATABASE [whatever] SET PAGE_VERIFY CHECKSUM  
GO

ALTER DATABASE [whatever] SET DB_CHAINING OFF 
GO

USE [whatever]
GO

CREATE USER [user1] FOR LOGIN [user1] WITH DEFAULT_SCHEMA=[db_owner]
GO

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hnakumAuthor Commented:
Very good
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.