sql-server

Why does this sproc reference find the correct table to update?

Hi, If I have tables like this: ImportSet1.Users ImportSet2.Users ImportSet3.Users Then in my sproc I do this: CREATE PROCEDURE [ImportSet2].[UpdateUsers] ... UPDATE Users set blah = 234 WHERE id = 234 This seems to work, but why? Since when did that prefix [ImportSet2] signify part of the table name? (in this case ImportSet2...

Do you recomend Sql Server for storing and indexing files (pdf, office, etc) ?

I need to storage and index files, like PDF and office files. Currently I'm using Sql Server 2k8 to perform this task using the Full text search with IFilters. My question is: Is this the "best" way? Should I switch, for instance, to Lucene for indexing? Thanks ...

What is API Usage?

I am not sure I am getting the correct definition for what API Usage is. I have a snippet of code that is used for a BulkInsert into SQL from c# application. It said the snippet shows the API usage. How do I translate that? private void WriteToDatabase() { // get your connection string string connString = ""; // connect t...

Visual Studio: ContextSwitchDeadlock

I have been getting an error message that I can't resolve. It originates from Visual Studio or the debugger. I'm not sure whether the ultimate error condition is in VS, the debugger, my program, or the database. This is a Windows app. Not a web app. First message from VS is a popup box saying: "No symbols are loaded for any call stack...

Query to fetch MsSQL table unique index and primary keys

SELECT sysobjects.xtype, syscolumns.name, sysindexkeys.indid, sysobjects.type FROM syscolumns LEFT JOIN sysobjects ON syscolumns.id = sysobjects.id LEFT JOIN sysindexkeys ON ( syscolumns.id = sysindexkeys.id AND syscolumns.colid = sysindexkeys.colid ) WHERE sysobjects.name = '{$table}' AND sysindexkeys.indid IS NOT NULL ORDER BY...

Useful system stored procedures in SQL Server

I recently discovered that I could use the sp_help to get a table definition and have been hooked onto it since then. Before my discovery, I had to open up the Object explorer in SQL Management studio, manually search for the table name, right click on the table and select Design. That was a lot of effort! What other system stored proce...

Is there any performance advantage to storing dates as ints in MS SQL Server

Either in terms of space or speed of queries and comparisons of fields? ...

what's the best practice for calling a webservice from within a trigger (SQL Server)

I have need to call a webservice when a particular column in a table changes. I can handle the deciding of which column changed in the insert/update/delete but I'm not sure how I should call the webservice. The webservice is offsite, we have a little control over it (we can ask for changes and get a reasonably quick response) but the s...

SQL Server Trigger - Send Message to Queue

Is it possible on a CLR trigger in SQL Server 2005 to send a message to a queue via MSMQ? I am using the SQL Server Project type, but System.Messaging does not appear as a reference I can add. Basically I need some type of action to take place (printing) when a row is written to the table. The device generating the row is a hand hel...

Easy way to add an ID column when there is data present

Is there an easy way to add an ID (Identity(1,1) & PK) column to a table that already has data? I have picked up a project that was freelanced out to a horrible developer that didn't put a PK, index or anything on the tables he made. Now that I am LINQ-ifying it, I have no PK to insert or update off of. ...

What should I do when I go over maxrecursion with a CTE?

I have a CTE that's doing some recursion. The easiest way to imagine the problem space is a resistor that is used in cars all over the world and you have all that information. Resistor A is used in Board B and C which is used in DashAssembly D,E,F...ZZ which is used in Car AAA, AAB and AAC. I got the CTE working with one part, checked ...

Software Architecture and Database Design: One database/web application per each company or one database/web application for all companies?

Hello gurus, I'm designing a web driven SQL database application from ground up. The application will manage information for clients that are in the same type of industry. In other words, the information (entities and relations among them) regarding each client does not vary too much from one to the next. However, the volume of the i...

SQL Server Check for IsNull and for Zero

I have the following: set @SomeVariable = @AnotherVariable/isnull(@VariableEqualToZero,1) - 1 If @VariableEqualToZero is null it substitutes the 1. I need it to substitute 1 if @VariableEqualToZero = 0 as well. How do I do this? ...

How to debug a CLR proc in VS2008?

Hi, I have written a CLR proc in VS2008 and deployed to SQL 2005 DB. I have set mode to debug and made sure my .sql script is set to run my proc. Have deployed with permission level to External and set db to be trustworthy on. But when I run the breakpoint is not hit and nothing seems to be happening. What am I missing please??? Ma...

Enforcing SQL Server connection string from SQL Server

I have a requirement from a customer that only DNS aliases may be used in application connection strings when connecting to SQL Server. Is there any way to enforce this from the server side? The point of doing this is to prevent hardcoding of IP addresses in applications, which may change with time. ...

How to check if a temporary table is existing in Database.

Hi, I am actually dropping a temporary table in Database. I have to delete only if it exists in the Database. Please let me know how to check if a table exists in Data base. ...

Select COUNT(*) of subquery without running it twice

I've got a procedure to return a result set which is limited by page number and some other stuff. As an OUTPUT parameter I need to return a total amount of selected rows according to the parameters except the page number. So I have something like that: WITH SelectedItems AS (SELECT Id, Row1, Row2, ROW_NUMBER() OVER (ORDER BY Row1) AS Po...

Is primary key always clustered?

Hi, Please clear my doubt about this, In SQL Server (2000 and above) is primary key automatically cluster indexed or do we have choice to have non-clustered index on primary key? ...

Change collation on clustered index column in SQL 2005

I have a Database that was created with an incorrect collation. I changed the collation of the database, but this left the individual columns with the incorrect collation also. This causes me a problem. So, I wrote a script to loop through and change the collation of the individual columns and this basically worked, except for a few col...

Do all SQL server versions rebuild indexes automatically or have a default rebuild criteria?

Do all SQL server versions rebuild indexes automatically or have a default rebuild criteria? I understand statistics are rebuilt automatically but not sure if indexes do as well. ...