sql-scripts

SQL Server - Running large script files

I have a database table on a development server that is now fully populated after I set it running with an import routine for a CSV file containing 1.4 million rows. I ran the Database Publishing Wizard on the table, and now I have a 286MB SQL script on my local machine. The problem is, I can't figure out how to run it. If I load it i...

How do I set a SQL Server script's timeout from within the script?

I have a large script file (nearly 300MB, and feasibly bigger in the future) that I am trying to run. It has been suggested in the comments of Gulzar's answer to my question about it that I should change the script timeout to 0 (no timeout). What is the best way to set this timeout from within the script? At the moment I have all of t...

In the Visual Studio SQL editor, how do I get rid of the boxes?

I usually create my SQL tables and stored procedures by writing a script inside Visual Studio. This works really well for me except for one simple annoyance: VS puts blue boxes around all the SQL queries and data-manipulation commands. The purpose of these boxes is to draw undue attention to the fact that VS thinks the query can be edite...

How to apply SQL scripts on a remote SQL Server?

I'm trying to completely automate my builds and part of it is applying SQL scripts to the SQL Server. I've created a batch file that calls SQL Server utility (OSQL.EXE) to apply scripts and it works if I call it directly on the SQL server. But I cannot use it on my build machine because it does not have SQL Server installed. Is there ...

SQL Server Script Wizard

Hi I am using SQL Server 2005. If I try to generate scripts for the dB using the Generate Scripts wizard in the management studio (Right click dB-> Tasks-> Generate Scripts) I get no option like IF EXISTS DROP condition in the list. Whereas some of the SQL Servers installed on different machines have this option enabled. Is the serv...

Microsoft .NET Framework Data Provider for Oracle problem executing scripts

We are having trouble executing scripts that begin with BEGIN and are having multiple procedures or triggers with the aforementioned provider. Execution of those fails. Has anyone eperienced similiar problems? ...

How can I su from root to db2inst1 and invoke a SQL script, in one line?

How can I su from root to db2inst1 and invoke a SQL script all in 1 line? I am thinking about something like this: su db2inst1 | db2 CONNECT TO myDatabase USER db2inst1 USING mypw; db2 -c -i -w -td@ -f /tmp/deploy/sql/My.sql | exit; Any ideas? ...

object_id() vs sys.objects

I use database scripts where I check for the existence of a Stored Procedure then drop it then create it. Which of the following would be more efficient for checking and dropping SPs Option 1 IF EXISTS(SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[myStoredProc]',N'P')) DROP PROCEDURE dbo.myStoredProc; Option 2 IF ...

Should I explicitly "SET IDENTITY_INSERT [Table] OFF" after turning "ON"?

Does SET IDENTITY_INSERT [Table] ON persist beyond the scope of a SQL Script? I'm wondering if I need to explicitly set it to "OFF" or if SQL Server knows that it should only use that setting for the current script. Thanks! ...

SQL Management Studio Express opening SQL scripts in Notepad

When I go to File > Open > File and select a .sql script, or even when I drag a .sql file into the SQL Management Studio Express window, it opens the script in Notepad which is totally useless when I want to run the script. Since this is on an external server (Windows 2003 Server), I end up having to disconnect from RDP, disable the loc...

Entity framework: ObjectContext get generated SQL change script?

Is there a way to get all the SQL change script of the object context? Note: I am not talking about ObjectQuery.ToTraceString(); ...

Does [My]SQL have a Pre-Processor-like Facility?

I'm writing a small deployment SQL script for my first database-driven app. In the process, I find that I repeat myself a lot, for instance: GRANT USAGE ON *.* TO 'foo'@'localhost'; DROP USER 'foo'@'localhost'; CREATE USER 'foo'@'localhost' IDENTIFIED BY 'password'; It would be fantastic if I could use a variable or a macro to replac...

SQL Server script: ALTER PROCEDURE - Executing multiple ALTER PROCEDURE into one script without having to select each of the ALTER one after another

I know this is not a big issue, but it tickles me anyway. I have a SQL Server 2005 script to create new data tables, constraints, altering some tables to add columns, altering procedures to take the table changes into account, etc. Everything runs fine until the script encounters my ALTER PROCEDURE statements. The error message is as f...

LINQ's FirstOrDefault in SQL script?

Hello! What is the SQL language keyword for the LINQ-to-SQL FirstOrDefault or SingleOrDefault? Is it TOP(1)? EXAMPLE: SELECT TOP(1) @ItemCode = ItemCode FROM VendorItem WHERE VendorId = @VendorId There can't be more than 1 results anyway since there is a Unique Key constranint, do I have to spell out the TOP(1) or whatever it is? ...

SQL Server: Stopping Queries Externally

Hello all, I run queries using SQLCMD utility via PHP and I wanted to know if there was a way to stop queries or scripts that I have executed via another SQL command by passing the process ID or something. I also make use of the PHP Driver for SQL Server would it be easier to do this way? Or is none of this possible - once a query run...

Abort MySQL script conditionally

Given: MySQL database. Sometimes db schema changes and updates are rolled out (in the form of sql script). In order to guarantee correct order of updates applied (no duplicate updates, no updates missing, etc) I plan to deploy the following solution: CREATE TABLE meta (name TEXT PRIMARY KEY, val TEXT); INSERT INTO meta VALUES ('version...

How to execute sql-script file using hibernate?

I gonna write several intergration tests which will test interatcion with db. For each test I need to have a certain snapshot of db. Each db snapshot saved in .sql file. What I want is to execute certain script file in certain test method, like this: @Test public void test_stuff(){ executeScript(finame.sql); ... testing logic ......

How to execute sql-script file in java?

I want to execute sql script file in java without reading all file contents to the big query and executing it. Is there is any standard way? ...

Quickly generate ascii text sql scripts based off of sql 2008 database

This is starting to frustrate me, mostly because it should be easy to do but I can't find anything. I am trying to version control my database. The method I have decided upon is to generate scripts at each check-in that creates a sql script for every object in my database. Most of my edits are done via the visual designer in SSMS and ...

Errors in database migration scripts

The following databases exist for each internally and independently developed software (web-based or client-server) application for a company: Development (D1 and D2) Integration Staging Testing Production The Production environment is shared between applications. Migrating applications requires: Run a script that changes the Prod...