sql-server

LINQ To SQL not saving to database

I have a very simple table and I can happily query it using LINQ To SQL, but when I do any save/updates the GetChangeSet method on my datacontext is always empty. My code is very simple (concatenated code from various classes): public static EntitiesDataContext EntitiesContext { get { return new EntitiesDataContext("Dat...

select from table, then form a space-separated string all in a stored procedure

Hi, I want to select about 4-5 rows from a table, then form a space separated string. All of this is to be done in a stored procedure (SQL server 2005). Is this possible? I will then use this space-separated string and save it to another table. Update SELECT * FROM Users WHERE userID < 10 output: john jake blah sam So, put thi...

Efficient ISNUMERIC() replacements on SQL Server?

So I just spent 5 hours troubleshooting a problem which turned out to be due not only to the old unreliable ISNUMERIC but it looks like my problem only appears when the UDF in which ISNUMERIC is declared WITH SCHEMABINDING and is called within a stored proc (I've got a lot of work to do to distill it down into a test case, but my first n...

Is VARCHAR like totally 1990s?

VARCHAR does not store Unicode characters. NVARCHAR does store Unicode characters. Today's applications should always be Unicode compatible. NVARCHAR takes twice the amount of space to store it. Point 4 doesn't matter because storage space is extremely inexpensive. Ergo: When designing SQL Server databases today, one should always use...

Recommended indexes for query in large table involving a 'date range' and an 'order id'

I have a query (which was created by LINQ to SQL) to get me a list of 'site visits' that were made between a certain date range which resulted in an order (orderid is not null). Theres nothing wrong with the query. I just need advice on creating the correct index for it. I was playing around trying different combinations on a production...

How to simply generate the CREATE SQL script for a table and data?

So i'm used to PHPMySQL where if I want to transfer a table from one database to another, I: go to the table click "export" CTRL-C go to the other database, insert SQL, CTRL-V In MS SQL Server 2008 Express, I try: right-click, script table as, CREATE TO but this only gives me the CREATE TABLE sql, not the INSERT INTO sql right-cl...

ideal design for winforms connecting to SQL Server . .

I have a winforms application that is doing the following: on each query: Db connect Db query Db disconnect as we are trying to avoid having to keep the db connection open. This suffers from performance as we have to connect / disconnect everytime. What is the idealized model here to have the fastest performance but without having...

Pivot using SQL Server 2000

I need some urgent help! I put together a sample scenario of my issue and I hope its enough for someone to point me in the right direction. I have two tables Products Product Meta I need a result set of the following ...

Why SQL Server go slow when using variables?

I have a sql query that runs super fast, around one second, when not using variables, like: WHERE id BETWEEN 5461094 and 5461097 But when I have: declare @firstId int declare @lastId int set @firstId = 5461094 set @lastId = 5461097 ... WHERE id BETWEEN @firstId and @lastId ... the query runs really slow, finishing only after ...

Update without locking inside a transaction

Is the following scenario possible in SQL Server using a single active connection? Inside a READCOMMITED transaction I need to update one table without locking it. For example each time I execute a statement I increase a field in that table. This operation doesn't need to be rolled back in case the transaction fails. Also, this update s...

Connections will not close when using Transaction Binding=Explicit Unbind; in connection string

I´m using Transaction Binding=Explicit Unbind in the connection string as recommended here since I´m also using TransactionScope with timeout. The problem is that the connections does not seem to close after being disposed and eventually there are no more connections available in the connection pool. I got the same result when I modified...

Windows domain changed cause sql2005 login fail

My company change the domain from abc to xyz and now i can't log into my local sql2005 via Windows login nor sql login. both login gave me this error: An error has occured while establishing a connection to the server. blah blah blah...Sql server does not allow remote connection. Error:26 - Error locating Server/Instance specified. i ...

Cross-database queries with different DB names in different environments?

How would you handle cross database queries in different environments. For example, db1-development and db2-development, db1-production and db2-production. If I want to do a cross-database query in development from db2 to db1 I could use the fully qualified name, [db1-development].[schema].[table]. But how do I maintain the queries a...

DTS- Debugging Tips

In a legacy project that I'm on, we have several processing that are preformed via DTS. DTS is not something I worked with a lot back in its hey day.... I was in college. More specificity, these process are in ActiveX code blocks -- which is basically VBScript for database. It is really hard to debug. Anyway, I'm wondering if any pas...

T-SQL: Opposite to string concatenation - how to split string into multiple records

I have seen a couple of questions related to string concatenation in SQL. I wonder how would you approach the opposite problem: splitting coma delimited string into rows of data: Lets say I have tables: userTypedTags(userID,commaSeparatedTags) 'one entry per user tags(tagID,name) And want to insert data into table userTag(userID,tag...

SQL Server 2005 drop column with constraints

Hi ! In Sql Server 2005 I have a column with a "DEFAULT" constraint. I'd like to create a script that drops that column. The problem is that is returns me that error : Msg 5074, Level 16, State 1, Line 1 The object 'DF__PeriodSce__IsClo__4BCC3ABA' is dependent on column 'IsClosed'. Msg 4922, Level 16, State 9, Line 1 ALTER TABLE D...

Finding a dependency of a SQL Server server data type

Is there a command, or a set of tables I can look at to determine which tables, stored procedures and views in SQL Server server 2005 have a certain user defined data type? ...

How to Get Last Created Entry's ID From Sql Database With Asp.Net

I will explain problem with an example: There is two table in my database, named entry, tags There is a column named ID_ENTRY in both table. When I add a record to table, entry, I have to take the ID_ENTRY of last added record and add it to table, tags. How can I do it? ...

What is the sql to query SqlServer system databases to find an DB object?

I have a large db with many tables and sprocs, and I want to find and see, for example, if there is a table with a name that has "setting" as part of it. I'm not very familiar with SqlServer's System Databases like master, msdb etc., I know there is a way to query one of those dbs to get what I need back, does someone know how to do it?...

SQL join to find inconsistencies between two data sources

I have a SQL challenge that is wracking my brain. I am trying to reconcile two reports for licenses of an application. The first report is an access database table. It has been created and maintained by hand by my predecessors. Whenever they installed or uninstalled the application they would manually update the table, more or less....