I am installing SQL SERVER 2022 from command line with this command:
SETUP.exe /IACCEPTPYTHONLICENSETERMS="False" /ACTION="Install" /ROLE="AllFeatures_WithDefaults" /IACCEPTROPENLICENSETERMS="False" /SUPPRESSPRIVACYSTATEMENTNOTICE="False" /QUIET="False" /QUIETSIMPLE="True" /UpdateEnabled="True" /USEMICROSOFTUPDATE="False" /SUPPRESSPAIDEDITIONNOTICE="False" /UpdateSource="MU" /FEATURES=SQLENGINE,REPLICATION /HELP="False" /INDICATEPROGRESS="False" /INSTANCENAME="SQLMYINSTANCE" /INSTALLSHAREDDIR="C:\Program Files\Microsoft SQL Server" /INSTALLSHAREDWOWDIR="C:\Program Files (x86)\Microsoft SQL Server" /INSTANCEID="SQLMYINSTANCE" /SQLTELSVCACCT="NT Service\SQLTELEMETRY$SQLMYINSTANCE" /SQLTELSVCSTARTUPTYPE="Automatic" /INSTANCEDIR="C:\Program Files\Microsoft SQL Server" /AGTSVCACCOUNT="NT AUTHORITY\Servicio de red" /AGTSVCSTARTUPTYPE="Disabled" /SQLSVCSTARTUPTYPE="Automatic" /FILESTREAMLEVEL="0" /SQLMAXDOP="0" /ENABLERANU="True" /SQLCOLLATION="Modern_Spanish_CI_AS" /SQLSVCACCOUNT="NT Service\MSSQL$SQLMYINSTANCE" /SQLSVCINSTANTFILEINIT="True" /SECURITYMODE="SQL" /SAPWD="@rquer0" /SQLTEMPDBFILECOUNT="1" /SQLTEMPDBFILESIZE="8" /SQLTEMPDBFILEGROWTH="64" /SQLTEMPDBLOGFILESIZE="8" /SQLTEMPDBLOGFILEGROWTH="64" /ADDCURRENTUSERASSQLADMIN="True" /TCPENABLED="0" /NPENABLED="0" /BROWSERSVCSTARTUPTYPE="Disabled" /SQLMAXMEMORY="2147483647" /SQLMINMEMORY="0" /IACCEPTSQLSERVERLICENSETERMS="True" /SKIPRULES="RebootRequiredCheck"
This creates a directory like this:
C:\Program Files\Microsoft SQL Server\MSSQL16.SQLMYINSTANCE\MSSQL
Is it possible to eliminate the number "16" just to make a more generic path? Maybe another param in command line or change an existing one?
You should be able to just change the parameter /INSTANCEDIR="C:\Program Files\Microsoft SQL Server\MSSQL16"
.
Why you would want to do this I don't know, it's a bad idea. Use standard folder names, then it's easy for others to understand the setup.
As far as your purported issue with running RESTORE
statements, you can parameterize it, and use SERVERPROPERTY()
to get the folder path (or just pass in an actual parameter). Instance names that are available on the machine can be got from the registry.
For example:
DECLARE @path nvarchar(261) = SERVERPROPERTY('InstanceDefaultDataPath');
DECLARE @mdfPath nvarchar(261) = CONCAT(@path, 'MYDB64SQLCMD.mdf');
DECLARE @ldfPath nvarchar(261) = CONCAT(@path, 'MYDB64SQLCMD.ldf');
RESTORE DATABASE MYDB64SQLCMD
FROM DISK = 'C:\TEMP\MYDB32.bak'
WITH
REPLACE, RECOVERY,
MOVE N'MYDB32' TO @mdfPath,
MOVE N'MYDB32_log' TO @ldfPath;