Create SQL user and delete SQL user

Source: Internet
Author: User

---------------------------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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.