automate script needed

  • i need a automate script to add new sqlinstance name, the script will take the machinename dynamically and we need to pass the instancename value\parameter.

    The servername below should be "machinename\inst1".

    EXEC Sp_addserver 'servername' ,'local'

  • What scripting framework are you using? Powershell, batch files with sqlcmd etc.

  • i am trying to create .cmd files .

  • As long as you have the sqlcmd file installed on the server from which you're executing the code, use the SQLCMD method to log onto the relevant servers. Check SQL Books Online for examples of the SQLCMD

    If you need to loop through a list of servers , and connect through to various servers , just create a txt file , read from the txt file, and loop and use the SQLCMD for every server.

  • just i need to run the automate script in one server at a time.

    The script should take the comutername dynamically and addthe servername as "computername\inst" .

    EXEC Sp_addserver 'computername\inst' ,'local'

    Note: 'inst' is standard.

  • Using SSMS you can add dynamically using this script.

    host_name() function will return

    the computername.

    declare @hostname varchar(200)

    select @hostname=HOST_NAME()+'\inst'

    select @hostname

    exec sp_addserver @hostname

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

  • thanks...

    I tried to changed the sqlinstance name with below script but its not changing the sqlinstance name.if i select @@servername then its showing the changed name but it is showing the same old sqlinstance name while connecting to databse engine .

    1.Ran the below script.

    DECLARE @var1 nvarchar(200)

    DECLARE @var2 nvarchar(200)

    SET @var1 = convert(nvarchar(50),@@SERVERNAME)

    set @Var2= HOST_NAME()+'\inst'

    EXEC sp_dropserver @var1

    EXEC sp_addserver @var2 , 'local'

    2.restart the sqlserver instance.

  • any suggession ?

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply