Create A Batch File To Run The Sql Statements
Oct 5, 2007
Hi
I have written stored procedures to create a database with db name as input parameter
I need to create a batch file to run the stored procedure with input value given in the command prompt along with the batch file will be my dbname, which will be used by the stored procedure to create the databse.
and also few sql statements to insert data into those tables after creating
Plz could any one help me out to create code to create a batch file
thanks in advance
View 4 Replies
ADVERTISEMENT
Oct 7, 2013
Is there a way to create a Batch file that will run an Update Statement and schedule it to run?I've used bcp to extract data to a txt file before, but i'm not sure if an Update can be performed.I'm using SQL Server 2008 R2 Express Edition so i don't have Server Agent available.
View 7 Replies
View Related
Apr 24, 2014
I have about 1200 sql files in one of my folders. Almost all of these files do data inserts and updates, so they should be run only once. As and when required I have manually ran around 150 of them already. Whenever I ran any of these scripts, I log that file name into a log table in my sql server including the execution time. Since running 1000+ more files takes a lot of time, I want to automate running of these files through a batch file. But I also want to filter the files that are already run.My file list looks like follows.
InsertToOrderTypes.sql
UpdateClientAddress.sql
DeleteDuplicateOrders.sql
InsertToEmailAddress.sql
ConsolidateBrokerData.sql
UpdateInventory.sql
EliminateInvalidOfficeLocations.sql
My log table in the database looks like this.
select * from sqlfileexecutionlog
FileNameRunTimeResult
---------------------
DeleteDuplicateOrders.sql03/12/2014 14:23:45:091Success
UpdateInventory.sql04/06/2014 08:44:17:176Success
Now I want to create a batch file to run the remaining files from my directory to my sql server. I also want to wrap each of these sql file executions in a transaction and log success/failure along with the runtime and filename into sqlfileexecutionlog table. As I add new sql files into this directory, I should be able to run the same batch file and execute only the sql files that have not bee run.
View 9 Replies
View Related
Aug 7, 2007
HELP,
I need to take a variable from a tabel in SQL Server pass to a Batch file and execute the batch file. Right now I can exec the batch file with XP_CMDSHELL but how can I pass the variable to the batch file and loop through all the variables.
Please help
Phil
View 4 Replies
View Related
Dec 5, 2006
I am using the following batch file to execute a script that creates a db and all its objects in the local sql express:
sqlcmd -S (local)SQLExpress -i C:CreateDB.sql
This works fine, but I'm wondering if there's an easy way to put the script in the batch file, so users don't have to worry about putting the script in the C drive. I tried getting rid of the i parameter and pasting the script from the sql file into the batch file, but it didn't work.
Thanks,
Dave
View 1 Replies
View Related
Sep 7, 2001
Hi,
I want to know if I can execute a set of batch statements ( basically create statements) during the installation of our product. I have used Access with ADP connected to MS SQL Server 7.0 and I am trying to merge the database and table creations with the installation procedure. Please tell me how I can go ahead with this. (I have tried using the installshield and some other similar products with not of much use).
Thanks in advance,
Mangala
View 2 Replies
View Related
Feb 25, 2015
I have an interesting problem. A number of spids are being blocked by a single select statement. The select statement is the same as returned from sp_who2, sysprocesses, sp_whoisactive of dbcc inputbuffer. It is not waiting on anything and has status as sleeping.
Clearly it is not 'just' a sleeping select statement as I can see over a thousand locks held by the spid on 2 user databases and tempdb. I'm working on the theory there is a begin transaction with a bunch of statements and no closing commit. But I want to be able to prove that. How can I show what statements were previously executed as part of this transaction?
Additional Info: SQL 2012 Enterprise Edition. This is a test server but is a reproduction of a live issue. At this point the application team cannot isolate the code causing the problem, only the set of processes the code resides in.
View 2 Replies
View Related
May 16, 2007
I am trying to use the Execute SQL Task to execute a very simple batch against the Oracle database:
Code SnippetTRUNCATE TABLE FactTable1;
TRUNCATE TABLE FactTable2;
TRUNCATE TABLE FactTable3;
TRUNCATE TABLE FactTable4;
TRUNCATE TABLE FactTable5;
I have an Oracle Connection Manager configured to source off of an Oracle 9i database. I have tried both the Microsoft OLEDB provider for Oracle and the native Oracle provider.
When I run the above statement in SQL Plus or SQL Workbench, it works just fine.
In fact, it works in SQL Plus and SQL Workbench like this as well:
Code Snippet
TRUNCATE TABLE FactTable1
/
TRUNCATE TABLE FactTable2
/
TRUNCATE TABLE FactTable3
/
TRUNCATE TABLE FactTable4
/
TRUNCATE TABLE FactTable5
Although both of these would introduce the need to probably do some expressions to add the ";" or "/" conditionally only if the target is Oracle (we are *trying* to have one package support both SQL and Oracle) neither works. I get the following error message from SSIS command window:
...failed with the following error: "ORA-00911: invalid character". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
Can anyone please provide some guidance on how to accomplish this with the Execute SQLTask task, taking into consideration that I very much generalize on the Oracle side?
Many thanks,
Rick
View 6 Replies
View Related
Apr 11, 2007
Hi all,
When I run the following T-SQL statement using SQLExecDirect with the SQL Server ODBC driver, it seems to indicate to me that the driver is somehow treating the SQL as a batch rather than a single statement.
Code Snippet
IF (1=1)
UPDATE MyTable
SET [Guid] = 'A663EC5D-A3AF-4391-8C45-9EBE87C9FD6C',
[Id] = 1
[FieldA] = 'Always run'
WHERE ([ID] = 1)
ELSE
INSERT INTO MyTable ([Guid],[Id],[FieldA]) VALUES (NEWID(), 2,'Never run')
Now the above statement is only a simplified statement to illustrate my problem, but I've also tested this stripped down version to ensure that I could replicate the problem with it.
Assuming I have the following table definition and data, I would expect that SQLExecDirect return SQL_ERROR due to the unique key constraint being violated on the [guid] column. However, I'm getting a SQL_SUCCESS_WITH_INFO error.
Code Snippet
CREATE TABLE MyTable
(
[Guid] uniqueidentifier,
[Id] int,
[FieldA] varchar(100)
)
INSERT INTO MyTable ([Guid],[Id],[FieldA]) VALUES (NEWID(), 1,'A')
INSERT INTO MyTable ([Guid],[Id],[FieldA]) VALUES (NEWID(), 1,'B')
According to a MS knowledge base article 195297:
In the version 3.6 SQL Server ODBC driver, SQLExecute, SQLExecDirect, or SQLParamData returns SQL_ERROR only if no other statements are executed after the first statement. If any other statements are executed after the first, even a simple RETURN statement with no return value, SQLExecute or SQLExecDirect returns SQL_SUCCESS_WITH_INFO
This makes me think that somehow the SQL Server driver is treating the T-SQL (with IF-ELSE) as a batch of statements (normally delimited with semi colon e.g. "statement1; statement2;").
I'm running MSDE, with SQL Server driver (SQLSRV32.DLL) v2000.85.1117.00 on Windows XP Professional SP2.
However, running the same SQL but changing the driver to the SQL Native Client (SQLNCLI.DLL) v2005.90.1399.00 returns SQL_ERROR as I expect.
Also the same SQL returns the desired error using both SQL Server and SQL Native Client drivers when connecting to SQL Server 2005.
So in summary:
Driver MSDE SQL Server 2005
{SQL Server} SQL_SUCCESS_WITH_INFO SQL_ERROR
{SQL Native Client} SQL_ERROR SQL_ERROR
Is there any settings that I need to set? Does anybody have any ideas?
Any help greatly appreciated!
View 3 Replies
View Related
Mar 3, 2014
I created a cursor that moves through a table to retrieve a user's name.When I open this cursor, I create a variable to store the fetched name to use within the BEGIN/END statements to create a login, user, and role.
I'm getting an 'incorrect syntax' error at the variable. For example ..
CREATE LOGIN @NAME WITH PASSWORD 'password'
I've done a bit of research online and found that you cannot use variables to create logins and the like. One person suggested a stored procedure or dynamic SQL, whereas another pointed out that you shouldn't use a stored procedure and dynamic SQL is best.
View 3 Replies
View Related
Nov 2, 2007
Hi all,
I have the "Northwind" database in my Sql Server Management Studio Express.
In my C:ProSSEAppsSamplesForChapter02Chapter02 folder, I have the following 2 files:
(1) ListColumnValues (MS-DOS Batch File)
sqlcmd -S .sqlexpress -v DBName = "Northwind" CName = "CompanyName" TName =
"Shippers" -i c:prosseappschapter02ListListColumnVales.sql -o
c:prosseappschapter02ColumnValuesOut.rpt
(2) ListColumnValues (Microsoft SQL Server Query File)
USE $(Northwind)
GO
SELECT $(CompanyName) FROM $(Shippers)
GO
When I ran the following SQLcmd:
C:ProSSEAppsSamplesForChapter02Chapter02>ListColumnValues.bat
I got the following "ColumnValuesOut.rpt" with error messages:
'Northwind' scripting variable not defined.
Msg 102, Level 15, State 1, Server L1P2P3SQLEXPRESS, Line 1
Incorrect syntax near '$'.
'CompanyName' scripting variable not defined.
'Shippers' scripting variable not defined.
Msg 102, Level 15, State 1, Server L1P2P3SQLEXPRESS, Line 1
Incorrect syntax near 'CompanyName'.
I copied these T-SQL statements from a book and I do not know how to correct them.
Please help and tell me how to correct these errors.
Thanks in advance,
Scott Chang
View 3 Replies
View Related
Jan 5, 2005
The Sql Server database can only see the local drive.
I would like to set up a batch file that will copy a SQL Server
backup file from the local drive to the network drive. I would
like to append the file date to the end of the copied file. I
assume a batch file can accomplish this but I am new to batch
file writing. Does anyone have code that they already created
for this sort of task??
Thank you!
View 13 Replies
View Related
Feb 21, 2008
I have create a batch file, that creates an ODBC then updates the application datasource key in the registry to the new system dsn name.
The problem is that the new DSN doesn't work when i try and connect the application...but if i had manually created the odbc source the app connects as expected... i have checked the registry and there is no difference between the two dsns created...but the application throws IM002[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified after i have also changed the applications registry key to point to the new database.
Now the interesting things to note are that when i re-create the odbc to the old server and database (sql 2000) by batch file it works fine. The new ODBC is linking to a sql 2005 database, but it is still using the 2000 drivers and when i manually created it, it worked also.
Another interesting thing is that if i go into the odbc dsn and click configure, go through and test the connection it works fine... after i close this i then retry the application and it opens correctly...
I need this to be automated with no manual intervention, as this will be added to a large group of users login scripts!
Any help greatly appreciated.
My batch file code is as below:
ODBCCONF.exe CONFIGSYSDSN "SQL Server" "DSN=RMS Live 2005 | SERVER=d-db99sql2005| Trusted_Connection=Yes | Database=RMS-Livedb"
View 4 Replies
View Related
Apr 19, 2006
I am new to writing SQL code and I read that you can use ALTER statements to create an index for a table. How would I go about doing that? Everything that I have tried in Query Analyzer comes up with an error.
Any help is appreciated.
View 3 Replies
View Related
Jan 27, 2007
I have some problems getting my SSIS package to run in a transaction, I wonder if anyone can assist.
What I want to do is run one package, which consists of a
- 1) create staging table SQL statement
- 2) read (all) from Access MDB to staging
- 3) copy (only new) from staging table to real table
- 4) drop the staging table
I changed the package to "require" a transactions, and left all containers in it to "supported" (default, I think). I left all the transaction type to default "serializeable".
The package does not work, since the table I created on step one is not "seen" when step 2 wants to insert into it. If I set the package transaction back to "supported" (default) the package works, but an error on step 2 or 3 will not rollback changes and not remove the staging tables...
So, my question really is: How do I make step 1 results visible to step 2 in the same transaction? Or do I need to take a completly different approach for this?
Stupid question I think, but I seem to not be able to find the right way to handle this situation...
Thanks for reading!
Ralf
View 4 Replies
View Related
Jan 22, 2002
hi,
I need some help in accomplishing this task.
I want to design a DTS task which will:
a)copy a certain given files from one directory to another
b)import the files into the tables
c)upon successful import delete the files from the original directory.
I done know much about scripting and need help in figuring out steps a) and c).
thanks
Zoey
View 2 Replies
View Related
Sep 13, 2001
Do u know how to write a batch file
for example i will need to type the sql server name it has to connect to the server and run a script that I have
let me know if u have any ideas of doing it
View 2 Replies
View Related
Sep 13, 2001
Do u know how to write a batch file
for example i will need to type the server name it has to connect to the server and run a script that I have
let me know if u have any ideas of doing it
View 3 Replies
View Related
Mar 29, 2000
Can someone show me an example of the syntax required to execute multiple BCP commands within the same batch (*.bat) file?
Sorry if this is a bit of a basic question, but not being a programmer by profession, I need to plead ignorance. I've tried a few things, but I just can't seem to figure it out.
Thanks!
Rich
View 4 Replies
View Related
Apr 3, 2007
Hi pals,
I need a small help from u all.
I need a Windows batch file script which does the ftp to remote machine and "puts" a file
say "data.xls" from a predefined dir say "c:uploads" and puts on the database server "d:dumps".
Regards,
Franky
View 2 Replies
View Related
Jul 20, 2005
I have a windows batch file that executes a SQL Server bcp command. Iwould like to obtain a return code if the bcp command fails. However,I cannot seem to find the return code (if any) for bcp. For example,if the bcp command is improperly formatted, or has a bad password, Iwant the batch file to return an error. Right now, my batch filesimply executes and returns success, even when the bcp command fails.Has anyone run into this before?Thanks!
View 3 Replies
View Related
Feb 15, 2001
Does anyone have any SQL that will look at a DB and dynamically generate CREATE INDEX statements? I
know I can use EM but I want to make this a scripted process and you can only generate CREATE INDEX statement if
you script out the tables too.
Any Ideas??
Thanks
View 2 Replies
View Related
May 6, 2008
MySql has a statement like:
SHOW CREATE TABLE tablename;
that returns the precise CREATE TABLE statement for the specified tablename.
Sql Management Studio also allows scripting Create Statement for any object by right-clicking it.
But I want to do this programatically, and fetch CREATE statements for Tables, Procedures & Views.
How can I retrive CREATE statements for Database objects progrmatically in Sql Server???
View 9 Replies
View Related
Mar 14, 2006
Hey all.. I am wanting my SQL Server installation to restart its services at a time I define in the Scheduled Tasks feature of the server its on
I need help with command line commands to:- Stop SQL Server Agent service- Stop and Start SQL Server service- Restart SQL Server Agent service
Thanks in advance
View 1 Replies
View Related
Nov 6, 2000
Hi all,
I am executing a backup batch job scheduled daily. It runs
successfully but havent backed up any of the databases. The message
is
"The name specified is not recognized as an
internal or external command, operable program or batch file."
I am trying this for a full day and i gave up..please can anyone help
me or suggest me what to do?..The same batch file is executed in all
servers and is working fine..
Thank you in advance
Rani.
View 2 Replies
View Related
Mar 31, 2000
Hi,
I would like to ask someone who could help me with one small problem:
I would like to run SQL server task on one of my servers, that will connect
to all other servers (including ones that are not SQL servers, ie: Exchange,
Test Server etc) one at the time, and that will execute one batch file (update.bat) that is residing on each server under C: drive.
Batch file will copy some things from all of the servers to one server.
Thanks, in advance.
Regards,
Vilko
View 1 Replies
View Related
Oct 21, 1998
Hi,I want to Utilize the schedule feature in window NT to run a batch file which will migrate data from a text file into an Sql server 6.5 table.
here is the senario,
I want to program window NT using AT,For, Start etc. I do not know how and have not yet succeeded. Please help?
the case:
I already wrote a code using bcp in a batch file as follow
if exist c:authors.out bcp pubs..authors in c:authors.out /Sservername /Usa /Ppassword /fp:autors.fmt
so the command line is basically if the file named authors.out exists in drive c: then run the bcp command. here is the problem, how can I run this code in the first place? A I going to use the AT command in window NT to run this code on a specific day and time to check if the author.out file exists.
Please help , I am in urgent need for a solution
You can write back to me at a.alhussein@mci.com
Thanks again for your time and effort to help me
regards
Ali
View 3 Replies
View Related
Jan 1, 2005
Dear All,
i need to put a query in a batch file to be easy to use by the user.
jusy only double click on it and it will work.
can any one help?
View 10 Replies
View Related
Apr 5, 2006
I'm trying schedule a batch file to run as a job from sql server agent. The batch file copies files from one server directory to a directory on another server. The batch file works properly when executed directly. The job is being executed under the sql service account login. I've given the service account access to both the source and destination directories.
When I try to run the job it fails with an "Access is denied" error on both the source and destination directories (as read from job history).
Any ideas?
View 4 Replies
View Related
Apr 15, 2004
Ok.. I thought I could do this but I can't get this to work.. I need to create a batch file to run an sql update statement.. This is simple but I can't get it to wortk.. How do I do it?
View 4 Replies
View Related
Jun 13, 2008
Hi All, I need to create a batch file to execute some 5-6 sql scripts. I have sql scripts for creating a table and related storedprocs and I need to generate a batch file to run all this scripts.
View 3 Replies
View Related
Sep 27, 2006
MS SQL Server 2005
i get the following error when trying to run this job as user1:
'Unable to start execution of step 1 (reason: Error authenticating proxy serv1user1, system error: Logon failure: unknown user name or bad password.). The step failed.'
and the following error when trying to run the same job as 'sql agent service account':
'Executed as user: serv1user1. The process could not be created for step 1 of job 0x3653ACCFFA46DD47B3703C87DDFD0717 (reason: 2). The step failed.'
>job:
job name: job1
server: (local)
connection: net1user1
owner: serv1user1
step type: operating system (cmdexec)
run as: user1
command:@echo off
copy C: est.txt C:folder
ECHO Job completed
PAUSE
>the sql server agent service is running under 'serv1user1' and works fine for other jobs running ssis packages.
>i have created the following credentials under security/credentials:
credential name: serv1user1
identity: serv1user1
password: same as sql server agent service
>i have created a proxy under the sql server agent/operating system (cmdexec):
proxy name: user1
credential name: serv1user1
active subsystem: operating system (cmdexec)
principals (sql login): serv1user1
thank you
View 2 Replies
View Related
Jul 25, 2007
Hi All,
I would like to embed some stored procedures in a batch file and execute it from the command prompt on windows.
I have no idea of how to embed a stored proc in a .bat file.
Can you please redirect me to the solution to this?
Thanks in advance
vishu
View 1 Replies
View Related