How to create a user in SQL

Why create a user in a database?

Users play a vital role in a database. Generally, permissions are given to users by the database administrator. The database administrator gives access to the username and password. We can create different users to carry out different tasks. We can also give permissions to our users depending on our needs.

How to grant session permission to a user

Before we create a user, we first need to connect to a system, and then create the user and grant permissions.

Creating a user with the session permission
Creating a user with the session permission

In the code above, we created a user and only gave the user permission for the session.

A user can only access the session of this database, and cannot perform operations like insert, delete, update, etc., onto the database.

When one tries to perform any operations on the database, it throws an error.

How to grant all permissions to a user

We can create a user and give it permissions to all the resources of the database.

A user can then perform all operations, like insert, delete, update, and select.

The user can utilize everything in the database if we grant all the permissions.

Creating a user with the all permissions
Creating a user with the all permissions

Free Resources