How can i access to sql server from windows batch - sql-server

I want to connect to Sql server and running some sql queries. How can i do that?
Thank you for helps..

Check out the SQLCMD utility:
http://msdn.microsoft.com/en-us/library/ms165702.aspx
Works not only on SQL Server 2008 Express, but also on the full versions, too.

You really need more detail in your question.
Based on my most common experiences, though, if you're just running some queries and putting the results somewhere, you'd want to create a SSIS (SQL 2k5 or 2k8) or DTS (SQL 2k5 and before) package and either have Windows schedule call the package or call it through your .bat file.

Related

devenv and dtsDebugHost in BIDS to Oracle

My SSIS package is connecting to Oracle and getting data (tns entry is there in tnsnames.ORA to connect to the Oracle schema.).
When I run my SSIS package in my SQL Server through BIDS (SQL Server 2008R2) its hitting the Oracle with devenv.exe and dtsDebugHost.exe.
How it will hit to Oracle if I run through SQL Server Agent Job. Will it be through dtexec.exe? I am not permitted to test it in my Production SQL Agent, So, please advice.
Yes, dtexec.exe will be the executable's name when you run this via SQL Agent (unless you do something special like run DTLoggedExec or write your own caller application)
Yes you will see dtexec.exe.
You need to make sure the Oracle Client is installed on the SQL Server - make sure choose the correct version 32 or 64 bit!
If the TNSNames are already installed on your production server then fine, otherwise I would recommend ditching TNSNames and maintaining within your package - makes things easier when you need to go live as it is one less thing to think about. You just need to copy the appropriate entry from TNSNames into the Server Name field:

Is there some way I can update the statistics on my SQL Server 2012 database?

I don't have the management studio installed and cannot install the express version as there seems to be a problem with my computer set up.
However I have VS2013 and I can open up query windows.
I created Indexes but then since then I have added a lot of new data. Is there some way I can update statistics for my SQL Server 2012 database from the SQL Script command line?
Try EXEC SP_updatestats to update all database statistics.
You can access the SQL command line using the tool sqlcmd that is installed as part of SQL 2012.
Here's a link to the update statistics command that you'll need to put together and execute.
http://technet.microsoft.com/en-us/library/ms187348.aspx
You can always create a script for the update statistics command, then execute that.
If you have both SQL and SQL Express installed, please make sure that you are connecting to the correct instance of SQL Server. the machine name alone or localhost should take you to the full sql 2012, (the default instance name for this is MSSQLSERVER) and the SQL Express should have an instance name of SQLEXPRESS (if I remember correctly) you'll need to use the naming convention server\instance to make the connection (you probably knew this bit already)
Try this
EXEC sp_updatestats;
MSDN

How to batch database modifications from SQL Server Management Studio

I'm struggling to figure out how to batch modifications to our databases in SQL Server Management Studio. We'll perform actions like editing columns, creating tables, renaming tables, etc. that we need to perform on all of our environments - but not until we're ready to push the application. I'm trying to use the SQL profiler to grab the SQL but this seems horribly inefficient.
Is there a solution built into the application that will track such changes for me?
Looks like I found my answer: http://www.mssqltips.com/sqlservertip/1723/auto-generate-change-scripts-in-sql-server-management-studio-ssms-for-tables/
you can easily create scripts using the osql utility if you are on a version lower than SqlServer 2005.
From sql server 2005 onwards we use sqlcmd

Automatically backup SQL Server database

I need to backup SQL Server database.
Is it possible to do this automatically without human intervention at regular intervals? If so yes then please suggest me how to do it and I'm using SQL Server 2005 Express Edition.
You'll need this:
http://www.codeplex.com/ExpressMaint
Then you can create a .cmd file to run it and schedule it using Scheduled Tasks. I can't give you an exact command line because your setup will be different from mine, but the docs are here:
http://www.sqldbatips.com/showarticle.asp?ID=27
http://www.sqldbatips.com/showarticle.asp?ID=29
There's a walkthrough on backing up SQL Server Express here
in sql 2005 scripts templates you will find backup script
from your code run this script in the time you want to backup your database
thats it i guess

SQL data comparison tool for SQL Server Compact

Does anyone know of a tool similiar to RedGate's SQL Data Compare that works with Microsoft SQL Server Compact 3.5?
For me the following process worked:
Install SQL Server Compact Toolbox extension.
Run the "Script database schema and data" command on both databases
Use a diff tool on generated files to see the changes.
In the end I solved this problem by Exporting my 2 SQL Server Compact Databases to SQL Server Express 2005 (although 2008 would work) using Data Port Console.
I then compared them using Red Gate SQL Data Compare.
This solution works just fine for me.
Not sure, but you could also have a look at the Apex SQL tools - Apex SQL Diff and Apex SQL DataDiff. There website is here. They don't specifically mention SQL Server Compact - but I'm sure you could inquire with them.
Red-Gate and Apex are my #1 choices for any kind of SQL tools :-)
Marc
Have you tried SQL Compare from starinix? They say it supports SQL Server (All Editions) so that may include compact edition.
This software does work as I have used it (for Yukon). It's also freeware which saves worrying about licensing.

Resources