Thursday, May 20, 2010

How to create Database,User Name and Password in Sql Server?

if db_id('TestDB') is null
begin
create database [TestDB]
end

if DATABASE_PRINCIPAL_ID('[TestDB]') is null
begin
use [TestDB]
if DATABASE_PRINCIPAL_ID('testlogin') is null
CREATE LOGIN [testlogin]
WITH PASSWORD='testpwd',
DEFAULT_DATABASE=[TestDB],
DEFAULT_LANGUAGE=[us_english],
CHECK_EXPIRATION=OFF,
CHECK_POLICY=OFF
end

if DATABASE_PRINCIPAL_ID('testlogin') is null
begin
use [TestDB]
CREATE USER testlogin
Grant Insert,Update,Delete,Execute,Select,Create Procedure to testlogin
end

No comments:

 
Feedback Form