microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
325 stars 57 forks source link

Add a command to create/add a user #312

Open yorek opened 1 year ago

yorek commented 1 year ago

It would be create if sqlcmd could support the creation of database users/logins. For example, something like

sqlcmd user add -u Davide -p <Password>

for adding a SQL user into the database pointed at by the active context, or

sqlcmd user add -u damauri@microsoft

for adding a AAD user

In both cases the users would be added to the database (creating the login if necessary) and then it would also be stored in the context config so that it could be used when generating the connection string:

sqlcmd config connection-strings -u damauri@microsoft
shueybubbles commented 1 year ago

what if sqlcmd dynamically set the initial password or prompted the user to type it? -P parameters on command lines are frowned upon these days. Would we need any hint parameters to distinguish a SQL auth user name from a Windows user name from an AAD user name?

yorek commented 1 year ago

That would work too. I would still allow to manually set a password, but I agree to make the default option the autogeneration

felipeschneider88 commented 1 year ago

You can use the command sqlcmd config add-user

I checked and the problem is with the help documentation. PS is using $Env:VariableName instead of SET VariableName

I manage to add an user with this code:

PS C:\Users\felip> $Env:SQLCMDPASSWORD="Passw0rd"
PS C:\Users\felip> sqlcmd config add-user --name felipe --username felipe --password-encryption none
User 'felipe' added
PS C:\Users\felip>
yorek commented 1 year ago

That doesn't create the login/user in the SQL Server database though.