sql-server

Default values in Insert Select in SQL

How to pass default values in the Insert Select construction in SQL? I have a table: create table1 (field1 int, field2 int, field3 int default 1337) create table2 (field1 int, field2 int) I want to insert table2 into table1 with a construction similar to this: insert into table1 select field1, field2, DEFAULT from table2...

backup SQL Server 2005 database without data

I have one stored procedure to backup the database. It will backup metadata as well as data. Is there any option to back up the database with out data. ie, back up only the schema (Empty tables). I don't want to script the database. ...

Copy trigger from one database to another

Is it possible, in a script executed in MS SQL Server 2005, to copy a trigger from one database to another? I've been asked to write a test script for a trigger my project is using. Our test structure is to create an empty database containing only the object under test, then execute a script on that database that creates all the other o...

Get all records that contain a number

It is possible to write a query get all that record from a table where a certain field contains a numeric value? something like "select street from tbladdress where street like '%0%' or street like '%1%' ect ect" only then with one function? ...

PHP Driver: If I KIll a PHP process will it also kill SQL Server Process (query)?

Hello all, I am using PHP SQL Server driver - is there a way to kill the last query sent by sqlsrv_query function? If not, if I kill the PHP process will it also kill the query in turn? I appreciate any help. ...

SQL server 2005 replication to many slave servers - hardware replication or change the strategy

Hi, we have a 500gb database that performs about 10,000 writes per minute. This database has a requirements for real time reporting. To service this need we have 10 reporting databases hanging off the main server. The 10 reporting databases are all fed from the 1 master database using transactional replication. The issue is that th...

SQL Server: Kill Process using Stored Procedure

Hello all, I want to modify the following as it doesn't seem to kill processes - I think its supposed to disconnect users (is this the same?). I want to be able to kill all process for a particular database - how can I modify the below: create procedure [dbo].[sp_killusers](@database varchar(30)) as ------------------------------------...

Is it possible to ceate a DSn to my FTP Account

hi, i using sql2005, my hosting company allow me to use 300mb for my sql server. i wand to increase my sql database size but i have 300GB is available in my FTP account. Is It possible to create a DNS (some thing like MS ACCESS below) to my FTP account <% ConnStringHB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath...

SQL query based upon object names stored within a table itself

Hi, I was wondering if there is a way of querying in MSSQL Server (2005 or 2008 or both) using table names / columns that are stored within a table themselves. Hopefully this makes sense but I imagine not so below is an example of what i mean, consider the tables: tableCollection ---------------------------- CollectionID ident p...

"Index was outside the bounds of the array" while Compare SQL schema by SQL compare tool

I got one problem from comparing database schema as i use Red gate SQL Compare 6 , after initialization of the compare databases error is coming as following "Index was outside the bounds of the array". Please provide your valuable comments to get resolve this issue. ...

SQL Server Stored Procedure - 'IF statement' vs 'Where criteria'

The question from quite a long time boiling in my head, that out of the following two stored procedures which one would perform better. Proc 1 CREATE PROCEDURE GetEmployeeDetails @EmployeeId uniqueidentifier, @IncludeDepartmentInfo bit AS BEGIN SELECT * FROM Employees WHERE Employees.EmployeeId = @EmployeeId IF (@Includ...

Cannot Connect to Sql Server Enterprise On Local Machine

Hi all, i've sql server 2008 enterprise edition, and a c# windows form code that should connect to server. it's a local server, on my computer, and when i try to log on i get this error cannot open database "Clients" requested by the login, the login failed. login faild for user crmsys. now, this user have the right permissions,...

SQL Server constraint Help

Hello there, I'm having problems coming up with an adequate restraint in SQL Server 2005. My problem involves the following tables: Table PKTable { pk integer primary key, property integer, } Table FKTable { pk integer primary key, fk integer references PKTable(pk), } I really want to make it impossible for a record, fk_rec...

Can a SQL Server database answer during a transaction?

I'm using .Net 2.0, ADO.NET, a dataset and data adapters to manage my data, and Microsoft SQL Server 2005 as database manager. I have an application that generates a great number of results (500K+) and saves them in a database. If one result generation fails, I would like to not save any of the results. So I put all the database inserts...

try catch not working in sql server 2005

Hey.. if i try to run following code in sql server 2005 i get error BEGIN TRY SELECT 1/0; END TRY BEGIN CATCH SELECT ERROR_NUMBER() AS ErrorNumber ,ERROR_SEVERITY() AS ErrorSeverity ,ERROR_STATE() AS ErrorState ,ERROR_PROCEDURE() AS ErrorProcedure ,ERR...

SQL Server CONVERT(NUMERIC(18,0), '') fails but CONVERT(INT, '') succeeds?

PRINT CONVERT(NUMERIC(18,0), '') produces Error converting data type varchar to numeric. However, PRINT CONVERT(INT, '') produces 0 without error... Question: Is there some SQL Server flag for this or will I need to do case statements for every varchar to numeric conversion? (aside from the obvious why?) ...

SQL Server 2000 compatible script

Hi, this T-SQL script works fine in SQL Server 2005 but in SQL Server 2000 it says incorrect Syntax near 'Try' 'End'. Any help please? Begin Transaction Begin Try UPDATE Test SET RefID = 'bc27de13-2323-4ce8-8c87-0171efbd812a' WHERE RefID = 'bc27de13-2323-4ce8-8c87-0171ffbd812a'; DELETE FROM Physician WHERE RefID = 'bc27...

Is it possible to create a SQL Server native file from c# (like BCP native format)

We are upgrading a 15 year old code-base, there is a requirement to create some native BCP formatted data files. In the new system, we would ideally like to utilize data in a C# DataTable object to create the data file in native BCP format. Can this be done and if so, what would be the best approach? ...

Count records by group with 0 number for records out of criteria

Hi, Need a rope ;)) Take a look on example: I have a table: CREATE TABLE [dbo].[test3]( [software] [varchar](50) NOT NULL, [result] [bit] NOT NULL, [computername] [varchar](50) NOT NULL ) With data: INSERT INTO test3 VALUES ('Adobe',1,'abc') INSERT INTO test3 VALUES ('Office',1,'abc') INSERT INTO test3 VALUES ('Adobe',0...

How to reconnect to a lost connection when it is lost using Linq to SQl automagically

i don't want to encapsulate every call in a try catch block is there an event i can subscribe to, for when a connection is lost or timesout so that i can reconnect.. or some way to not check every linq query. and if not why not! Edit: Does Linq to Entity's have this? Edit: I'm using Microsoft SQL Azure, and it drops connections alo...