---------------------------create a SQL user and associate the database-----------------------------create a new SQL user, associate a Windows user connection to the SQL database create Login [huang-pc\fly_user] from windows with default_database=[fly]--pc\ User: Includes Windows users and groups, as well as domain users and groups. --fly: The database name that the user is associated with by default. /*--Create SQL Server user create login [sql_user] with password=n ' 123123 ' MUST_CHANGE, Default_database=[fly], check_expiration=off, check_policy=on--sql_user: User name. --must_change: The next login must be modified. --default_database: Default database. --check_expiration: Force password expiration. --check_policy: enforces password policies. */go--CREATE database user name Use [fly]gocreate user [fly_user] for login [huang-pc\fly_user] with default_schema=[dbo]--fly_user: Naming can be inconsistent with user names. --dbo: schema name----------------------------Delete database user and SQL user----------------------------Delete database user if exists (select * from fly.sys.database_principals where name = n ' Fly_User ') DROP USER [Fly_User]ELSE print ' Do not have this database user ' go--Delete SQL login user If exists (select * from msdb.sys.server_principals where name = n ' Huang-pc\fly_user ') drop login [huang-pc\fly_user]else print ' no this SQL login user '--------- ----------------------------------------------------------------------
This article is from the "Tianya Ronin" blog, please be sure to keep this source http://gongxi.blog.51cto.com/4691965/1908068
Create SQL user and delete SQL user