sql-server

Using the results of a query in OPENQUERY

I have a SQL Server 2005 database that is linked to an Oracle database. What I want to do is run a query to pull some ID numbers out of it, then find out which ones are in Oracle. So I want to take the results of this query: SELECT pidm FROM sql_server_table And do something like this to query the Oracle database (assuming that the ...

What is the best way to check for the existence of a Login in SQL Server 2005.

I am looking for the best way to check that a database login exists in SQL Server 2005. I am currently using IF suser_sid('loginname') IS NOT NULL but suser_sid() returns a value in some cases where a login does not exist. In SQL 2000 we use SELECT * FROM [Master].[dbo].[sysxlogins] WHERE [name] ='loginname' but that table does...

Prevent mutually recursive execution of triggers?

Suppose you have the tables Presentations and Events. When a presentation is saved and contains basic event information, such as location and date, an event will be created automatically using a trigger. (I'm afraid it's impossible for technical reasons to simply keep the data at one place and use a view.) In addition, when changing this...

Linked Server Error using MSDTC

I am Showing An example of Stored Procedure For Data Transaction using "Linked Server" Between Two System Through Internet Alter Proc [dbo].[usp_Select_TransferingDatasFromServerCheckingforExample] @RserverName varchar(100), ----- Server Name @RUserid Varchar(100), ----- server user id @RPass Varchar(100), ---...

How do I run that database backup and restore scripts from my winform application?

I am developing a small business application which uses Sqlserver 2005 database. Platform: .Net framework 3.5; Application type: windows application; Language: C# Question: I need to take and restore the backup from my application. I have the required script generated from SSME. How do I run that particular script (or scripts) from m...

Determine if table exists in SQL Server CE?

I know this is similar to this question, but I'm using SQL Server CE 3.5 with a WinForms project in C#. How can I determine whether a table exists? I know the IF keyword is not supported, though EXISTS is. Does information_schema exist in CE where I can query against it? Thanks. ...

How do you run a 300mb+ MS SQL .sql file?

I use RedGate SQL data compare and generate a .sql file so i can run it on my local machine but the problem is the file is over 300mb and i can't do copy and paste because the clipboard won't able to handle it and when i try to open the file in sql management tool. it give me error compiling about the size. is there a way to run large ....

NHibernate generated GUID - field type

Hi, I'm new to NHibernate. If I use NHibernate to generate GUIDs for inserts to MS Sql2005, what type does the id field in the db need to be. Any help appreciated. Thanks ...

How to make sure redundant data is deleted in a many-to-many relationship

Hi folks, I'm trying to make sure some data is auto-deleted when there's no more references using cascade deletes. I'll explain with a fake database based on Stack Overflow. I have a Post table. Each post has zero to many Tags. So it should look like: Post <-> PostTags <-> Tags eg. Post 1 has tags 'A', 'B', 'C' Post 2 has...

How can I use a List<> as the condition for my where clause with Linq?

So I've been banging my head against the proverbial wall for a few hours and I thought I'd see if anybody else has solved this problem before... I have a List<string> of values that I want to use as filters on a search. In the olden days I would build a string of WHERE field = 'a' OR field = 'b' OR field = 'C' into the query. But with L...

Data Modeling: What is a good relational design when a table has several foreign key constrainst to a single table?

Hi there! I have 2 tables: 1. Employees 2. Vouchers Employees table has a single primary key. Vouchers table has 3 foreign key constraints referencing the Employees table. The following is a sample T-SQL script (not the actual table script) to create both tables and their relationship in SQL Server: IF OBJECT_ID('dbo.Vouchers') IS N...

Bi-Directionnal Replication With SQL Server

Hi, Is there a way to make a bi-directionnal Replication with SQL Server ? (BDD 1) Table 1 <=> (BDD 2) Table 1 Thanks. ...

Data driven design problem - data counting

I want to provide about 10 different 'statistics' to my users. Each stat represents the count returned by a different query of my database. Each stat/query is specific to the current user. What is going to be the most efficient way to achieve this? Am I right to think that running the stat queries, for each user on each page of my site (...

SQL Server Management Studio as Application Platform

Could the SQL Server IDE ever become an application development platform for enterprise applications? In a similar way to the old xBase applications, but, you know, better? The main reason is that the Management Studio is one of the best “data centric” application I’ve ever used. It has most of the main ingredients for the proposed solu...

What is your preferred document format for documenting databases

I am in the process of writing an application which, among other functionality, generates MediaWiki documentation of an MSSQL database (objects, tables, table data). My question is which document formats you prefer, or are required to produce. I have too many ideas to follow, so your answers should set my priorities ;) (I know there ar...

sql to detect fields modified in update trigger ( sql server 2005 )?

In sql server 2005 , inside an update trigger is there a way to find the list of fields\columns those are modified by the original update query. I have a table with 150 columns and inside the trigger need to konw if ONLY one particular field was updated or not ( and no-other field was modified ) I can write a long sql to compare 150 c...

Choosing adequate spec servers for ASP.NET application

Hi, I'm working on an application that's due to launch soon and could do with some advice on how to go about choosing servers of the appropriate configuration so everything performs well. The app is .NET 3.5, using SQL express edition for the DB. We currently have one low spec server being used as a staging environment for testing, it'...

How do you handle user input during full-text search on ms sql server?

Hi all, I have a simple search mechanism on ms sql server that uses full-text "contains". I pass search value as a parameter to contains predicate - directly from user's input (via asp.net web site). The problem is that i get sql exception in variety of cases: - when user inputs two words, like 'simple case' - when user adds qoute to se...

Full-Text Index Comparisons in SQL Server 2005 Express

How does one compare the text field of one record to all the other records in SQL server to return, for example, the top 5 most related records? An example of the functionality I'm after are the various Related Posts plugins for Wordpress that produce a list of links to posts related to the post currently being viewed. Cheers, Iain ...

"Where IN" with multiple columns (SQL Server)

I'm Using SQL Server 2005. The query would look like this Select col1, col2, col3 from where (col1,col2) in SQL Server doesn't seem to like that, any way of implementing that that anyone knows of that doesn't involve converting to varchars or anything else messy? This is the actual query. SELECT * FROM ( SELECT NEWI...