Backup DB on Remote SQL Server Express - sql-server-2005

I need to create a TSQL script to backup a db on a remote SQL Server Express (2005). I have a SQL Server 2005 on another box. Not sure how I can run the script from this SQL Server 2005 to do the backup job.
The script is something like this:
RESTORE DATABASE [myDB] FROM DISK = N'C:\Tmp\myDB.bak' WITH FILE = 1,
NOUNLOAD, STATS = 10
Actually, I tried this SQL script on the remote SQL Server Express by using SQL Server Management Studio Express and it runs OK. The reason I ask this question is that I can schedule a job on SQL Server 2005, but I cannot create a schedule job on the remote SQL Server Express.
Another way, I think, is to create a SQL SP on the SQL Server Express first. Then I'll write a simple console application to connect to the SQL and run the SP as a Windows Scheduled job.

There is no need to do this by TSQL. SQL Server (also Express) includes a utility called sqlmaint.exe, which allows you to perform backup operations on a local or remote SQL server. Simply write a batch file calling sqlmaint with the correct command line parameters (documentation) and put this batch file in Windows Scheduler.
If you still want to do it by TSQL, SQL Server also contains osql.exe, which allows you to execute arbitrary SQL statements on a local or remote server. Again, you can automate it using simple batch files.
EDIT: If you want to call the TSQL script using your own application, it might be helpful to know about your programming language or data access technology of choice.

Related

How to Execute SQL Server query (procedure) from another PC in network

Situation now
We have a netrowk set up. Some PCs have SQL Server 2012 installed, some don`t.
Is it possible to write a stored procedure and have it invoked/executed by another user/PC without SQL Server? For example by some .bat/.cmd script, I don`t know.
Desired situation
I write SQL query on my SQL Server management studio.
I save the query as a stored procedure. <-- up to here I am OK.
I do something that makes the procedure availible to other users. The advice I get from this question (I hope).
Other colleagues execute the procedure.
They get a result of the query in a CSV.
The client computers that need to run the stored procedure could install the sqlcmd utility. This allows for the execution of sql commands on another SQL Server.
SQLCmd -S<<SERVERNAME\INSTANCENAME>> -Q "Execute dbo.YourStoredProcedure"
And then have your stored procedure save the CSV file to a network drive or send it via e-mail.
Another way to retrieve data could be using the BCP utility. In this way the user could connect to your server, execute the query and receive a CSV file to a specified location on their computer.
In both cases it involves installing an additional program on the client computer.
You don't need SQL Server installed in the client machines to run queries or execute procedures. At most, depending on which programming language you are are using, you need the client installation for SQL Server. This is true for any DBMS, even Microsoft SQL Server 2014.
If you implement you code in Java, for example, you don't need even the MS SQL Server client. The JDBC driver for MS SQL Server is enough. It can be download from Microsoft and is not part of the SQL Server client installation.

SQL Server 2008 Express - How to update my local database to server database

I have assigned to update my server database from local database (both running with SQL Server 2008 Express). I have many new data on my local and now I want to move all to server but without changing servers data. Is there any way I can do it automatic?
You can alsouse tools which generate diff scripts, like this one for schema or see here

SQL Server 2005 - How to restore multiple backups (.bak)

I need to restore near 40 databases (.bak files) to a new SQL Server 2005 instance.
Manually, from SQL Server Management Studio, takes a long time.
¿How can I restore automaticaly all the .bak files to the new Server?
The new SQL Server instance is empty.
Thanks for the help!
SQL Server backups can be scripted like, literally, everything else. You can find out about it on Google. Search for "SQL Server restore statement".
Let me quote commenter Murph who had a very nice idea:
Its easier than that to get the script - when you do a restore with
SQL Server Manager you get the option to create a script instead of
run the restore, that will give you the basis from which you can build
all the scripts you need.

How to get Bak file or MDF without close connection sql server?

i have a database (ms 2005 server). How to get bak or mdf file BUT; it is running windows 2008 server also over 600 stuffs is using this DB. if i get .bak file or mdf. i must close connection. i dislike it. is there any useful methods or method to get BAK or MDF? this method may be a EXE or ms sql property or tool?
You certainly do not need to drop users to make a backup. Just right click your database in SQL Server Management Studio -> Tasks -> Back Up
Even better, setup a regular backup schedule.
Here's further instructions on backing up SQL Server 2005.

Creating SQL Server 2000 database using SQL Server 2008

My development machine has SQL Server 2008 Developer edition on it. A production server I am going to do some development for has SQL Server 2000 on it. Is there a way to create a 2000 database using my 2008 developer edition? Or do I need to create it on the 2000 server and move it to my development machine?
It will not be possible to move the development database into production. Once a database file has been upgraded to the SQL 2008 format, it is impossible to downgrade to SQL 2000 format.
You should focus your development on creating T-SQL scripts instead of creating database objects. This includes initial database creation and any subsequent schema changes. Perhaps you can use a version based approach for your schema and catalog data. As long as you don't use any SQL 2008 specific functionality, the scripts will run fine on SQL 2000.
Setting the db compatibility level to 80 on development will help making the behavior of the 2008 server closer to the 2000 server, but it does not mean the 2008 specific features will not be usable. You have to pay attention and make sure every functionality and feature you use in development will also be available in SQL 2000.
create a database in 80 compatibility mode and you should be ok with regards to sql you use. but you can't restore a 2008 db on a 2000 server.
I suggest you try it this way:
If your SQL 2008 database, right click, select Tasks, Generate Scripts. Now select your database, select your options in the next window (like script Drop, script Data...), continue through the wizard until Finish.
Now SQL will make your qualified script and it is ready to run.
It depends on how you're going to get the new database back to the production 2000 server; if you create it in your 2008 instance, you can't back it up and restore it to 2000, even if you create it in compatibility 80 as Mladen noted; but you could generate scripts to export your database to the 2000 instance, as long as you don't have to copy any of the data in the tables.
If you need to do a full backup and restore of the new database, you'll be better off with a 2000 instance to connect to for development, MSDE could be installed as a named instance alongside the 2008 edition.
yes, the database can;'t be restored from SQL 2008 even with 80 compatibility on SQl 2000 instance.
If you have to restore , script the DB and objects and recreate them on SQl 2000.
-Ashok