w3resource

SQL change password

Change Password

Following the standard SQL syntax for changing passwords for users, we have discussed how to change passwords in different database platforms like DB2, Oracle, MySQL, PostgreSQL, and Microsoft SQL Server.

SQL Syntax:

GRANT CONNECT TO username IDENTIFIED BY password

Parameters:

Name Description
username A username.
password Password for the username.

NOTE: A DBA or somebody with sufficient privilege can change the existing password of a user and create a new user.

DB2 Syntax:

CONNECT TO DatabaseName USER userid 
USING password NEW new_password 
CONFIRM confirm_password

Parameters:

Name Description
DatabaseName Database to which the user is permitted to be work.
userid User id of the user whose password you are changing.
password Old password.
new_password New password.
confirm_password New password.

Oracle Syntax:

ALTER USER username IDENTIFIED BY password

Parameters:

Name Description
username A username.
password Password for username.

MySQL Syntax:

SET PASSWORD FOR user = PASSWORD('some password') | 
OLD_PASSWORD('some password') | 'encrypted password'

Parameters:

Name Description
user Username and hostname.
some password Password for username.
some password Old password for that user.
encrypted password Encrypted password.

PostgreSQL Syntax:

ALTER USER username WITH PASSWORD password 

Parameters:

Name Description
username A username.
password New password for username.

SQL Server Syntax:

ALTER LOGIN loginName WITH PASSWORD = password 

Parameters:

Name Description
loginname Specifies the SQL Server login for which the database user is being created.
password Specifies the password for that user.

Here is a new document which is a collection of questions with short and simple answers, useful for learning SQL as well as for interviews.

Check out our 1000+ SQL Exercises with solution and explanation to improve your skills.

Previous: Create users
Next: Create role statement



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/sql/database-security/change-passwords.php