sql-server

How can I set default seed for all identities within a SQL Server database?

Is there a way to tell SQL server to use specific default seed value for IDENTITY columns - assuming the (to be run) CREATE TABLE statements do not specify one? I don't really care about altering existing data or altering the seed values for specific IDENTITY columns. I want the same seed for all newly created identity columns. Assume I ...

How do I remove database name from SQL Server generated script?

Anytime I use 'script table as' -> 'Insert To' (or other command), the script generated automatically places the database name in the script. Such as: INSERT INTO [DatabaseName].[dbo].[tblToBeInserted] ... While not a huge problem to just delete it, it has slipped by a few times and the script breaks if run on a different server with a...

SQL connection to database repeating

ok now i am using the SQL database to get the values from different tables... so i make the connection and get the values like this: DataTable dt = new DataTable(); SqlConnection connection = new SqlConnection(); connection.ConnectionString = ConfigurationManager.ConnectionStrings["XYZConnectionString"].Connectio...

Querying a smalldatetime's date and time seperately in SQL server?

Imagine a table that has two fields, a smalltimedate and an int and about 1000 rows of data. What I'm attempting to do in query is to find the average of the INT field for rows between 3/3/2010 - 3/13/2010 and only if the entry is between 6:00am - 11:00pm. I tried between '2010-03-03 06:00 AND 2010-03-13 23:00' However that only rest...

syntax for single row MERGE / upsert in SQL Server

I'm trying to do a single row insert/update on a table but all the examples out there are for sets. Can anyone fix my syntax please: MERGE member_topic ON mt_member = 0 AND mt_topic = 110 WHEN MATCHED THEN UPDATE SET mt_notes = 'test' WHEN NOT MATCHED THEN INSERT (mt_member, mt_topic, mt_notes) VALUES (0, 110, 'test') Resolution per ...

Can I Use EF Across Multiple DBs in One SQLServer Instance?

Hello, I have been searching the blogs and articles but I have not found much support for this scenario. I have been poking around EF and realized that I could create views that contained data from multiple databases and then build the EF object model off of those views. Although it works I am not sure about the usual issues of performa...

How do I intercept ADO.Net calls including SqlDataSource?

I'm interested in making a generic tool to log database calls in ASP.Net by page so I need the stack trace as well. Idea is similar to http://l2sprof.com/, but for straight ADO.Net. Essentially I want to make a tool I can add to any project that can generate some statistics by page/class of # of calls and what calls are made so I can g...

How efficient is a details table?

At my job, we have pseudo-standard of creating one table to hold the "standard" information for an entity, and a second table, named like 'TableNameDetails', which holds optional data elements. On average, for every row in the main table will have about 8-10 detail rows in it. My question is: What kind of performance impacts does this ...

Is the RESTORE process dependent on schema?

Let's say I have two database instances: InstanceA - Production server InstanceB - Test server My workflow is to deploy new schema changes to InstanceB first, test them, and then deploy them to InstanceA. So, at any one time, the instance schema relationship looks like this: InstanceA - Schema Version 1.5 InstanceB - Schema Vers...

how to rethrow same exception in sql server

I want to rethrow same exception in sql server that has been occured in my try block. I am able to throw same message but i want to throw same error. BEGIN TRANSACTION BEGIN TRY INSERT INTO Tags.tblDomain (DomainName, SubDomainId, DomainCode, Description) VALUES(@DomainName, @SubDomainId, @Domai...

sync data from main sql server into sql ce databases

Hi there, I am wanting to sync data between a SQL 2008 DB and some SQL CE. It's only a one way requirement, so when data is updated in the main SQL server the updates are sent to the CE databases. Is this easy to setup with the sync framework. I was able to find a demo, however I couldn't compile it. ...

Best practice stock management when payment of customer failed using SQL Server and ASP.NET

Hi there, I am currently building a webshop for my own where I want to increment the product-stock when the user fails to complete payment within 10 minutes after the customer placed the order. I want to gather information from this thread to make a design decision. I am using SQL Server 2008 and ASP.NET 3.5. Should I use a SQL Server ...

How to Deal with SET ANSI_NULLS ON or OFF ?

I want to call this procedure that sends one value that can be NULL or any int value. SELECT DomainName, DomainCode FROM Tags.tblDomain WHERE SubDomainId =@SubDomainId I simply want to use this single query rather than what i m doing right now in below given code. I searched for this how could i do this then i got this Link. Accordi...

How to Delete all data from a table which contain self referencing foreign key

I have a table which has employee relationship defined within itself. i.e. EmpID Name SeniorId ----------------------- 1 A NULL 2 B 1 3 C 1 4 D 3 and so on... Where Senior ID is a foreign key whose primary key table is same with refrence column EmpId I want to clear all rows f...

Why are these two sql statements deadlocking? (Deadlock graph + details included).

Hi folks, I've got the following deadlock graph that describes two sql statements that are deadlocking each other. I'm just not sure how to analyse this problem and then fix up my sql code to prevent this from happening. Main deadlock graph Click here for a bigger image. Left side, details Click here for a bigger image. Right sid...

Resources for high performance SQL Server database design

I'd like some suggestions for online resources (blogs, guides, etc - not forums) to help me become good at designing high performance SQL Server databases that operate with large amounts of data and have heavy loads in terms of data turnover and queries per minute. Suggestions? EDIT The load I'm talking about is mainly in terms of dat...

Keeping DB Table sorted using multi-field formula (Microsoft SQL Server)

I have a JOB table, with two interesting columns: Creation Date Importance (high - 3, medium 2, low - 1). A JOB record's priority calculated like this: Priority = Importance * (time passed since creation) The problem is, every time I would like to pick 200 jobs with highest priority, and I don't want to resort the table. Is t...

How to pass a variable number of parameters to a SQL Server stored procedure ?

I used SQL Server 2005 for my small web application. I Want pass parameters to SP . But there is one condition. number of parameter that can be change time to time. Think ,this time i pass name and Address , next time i pass name,surname,address , this parameter range may be 1-30 , ...

Please help debug this ASP.Net [VB] code. Trying to write to text file from SQL Server DB.

I am a PHP programmer. I have no .Net coding experience (last seen it 4 years ago). Not interested in code-behind model since this is a quick temporary hack. What I am trying to do is generate an output.txt file whenever the user submits new data. So an output.txt file if exists should be replaced with the new one. I want to write dat...

How to ensure DB security for a Windows Forms application?

The basic setup is classic - you're creating a Windows Forms application that connects to a DB and does all kinds of enterprise-y stuff. Naturally, such an application will have many users with different access rights in the DB, and each with their own login name and password. So how do you implement this? One way is to create a DB logi...