sql

How to store a list in a db column

I would like to store an object FOO in a database. Lets say FOO contains three integers and a list of "Fruits". The list can have any length, the only thing I know is that the all the fruits allowed are stored in another table. Can I store the fruit list in a column? ...

sql statistics io scan count explanation

Hi, Simple question, but I haven't found a good explanation on google. When using Set Statistics IO ON, the logical reads and scan count is provided in the message window of management studio. If I have: tblExample, scan count 5, logical reads 20 What does scan count signify? ...

SQL: Get value at index in binary value

Is there a SQL command that could be used in a query, stored procedure, function, that would work against a Binary Type similar to the following C# code? if (someBinaryArray[index] == 0) { ... I'm wanting to check if an index of a position in the binary is a certain value instead of pulling the entire array down and doing the compari...

Why doesn't this SQL statement work?

SELECT * FROM table1, table2 WHERE table1.user_id = table2.id AND table1.content = news AND table1.content_id = 1 that wont work. cant u have two "AND" in a sql statement?? //Tomek ...

SQL Server 2000 - Query a Table’s Foreign Key relationships

Nearly identical to http://stackoverflow.com/questions/85978/query-a-tables-foreign-key-relationships, but for SQL Server 2000 For a given table 'foo', I need a query to generate a set of tables that have foreign keys that point to foo. ...

How do I set a column value to NULL in SQL Server Management Studio?

How do I clear the value from a cell and make it NULL? ...

SQL - Use results of a query as basis for two other queries in one statement

I'm doing a probability calculation. I have a query to calculate the total number of times an event occurs. From these events, I want to get the number of times a sub-event occurs. The query to get the total events is 25 lines long and I don't want to just copy + paste it twice. I want to do two things to this query: calculate the numb...

Left outer join on two columns performance issue

I'm using a SQL query that is similar to the following form: SELECT col1, col2 FROM table1 LEFT OUTER JOIN table2 ON table1.person_uid = table2.person_uid AND table1.period = table2.period And it's either way too slow or something's deadlocking because it takes at least 4 minutes to return. If I were to change it to this: SELECT col...

SQL/T-SQL - how to get the MAX value from 1 of N columns?

In SQL/Transact SQL, I am trying to update a temp table to take the latest date from 3 different date columns (in that temp table), and put that MAX date into a "latest date" column. What is the best way to do this, using an update statement? ...

sync SQL Server 2005 login passwords

Background: We are running a web application where each user has a login to the system. The application login is mapped to an actual SQL Server 2005 login (which we needed to create). Our development and disaster recovery sites are simply copies of this setup. On a nightly basis, the production database is backed up, the dump is archi...

Use linq to generate direct update without select

G'day everyone. I'm still learning LINQ so forgive me if this is naive. When you're dealing with SQL directly, you can generate update commands with conditionals, without running a select statement. When I work with linq I seem to follow the pattern of: Select entities Modify entities Submit changes What I want to do is a direct u...

PHP / MySql Verbosity VS over the wire

I have been starting to write some reasonably large and or confusing MySQL queries in PHP. I am trying to find a balance between verbosity and performance... If performance has anything to do with it or not is my question. It being white space and MySQL comments inside of my queries. It would make sense to me that PHP would filter the q...

Fixing DB Inconsistencies - ID Fields

I've inherited a (Microsoft?) SQL database that wasn't very pristine in its original state. There are still some very strange things in it that I'm trying to fix - one of them is inconsistent ID entries. In the accounts table, each entry has a number called accountID, which is referenced in several other tables (notes, equipment, etc. ...

Is SQL the assembly for databases?

Talking about hibernate and others ORMs, the ORMs evangelists talk about SQL like the assembly language for Databases. I think is soon to assert this, but I guess can be true on a near future, not sure. UPDATE: The analogy I was referring means SQL is to assembly what ORM is to C/Java/C#. Of course, an exact analogy is not possible. Th...

Linq to SQL: execution order when calling SubmitChanges()

I have 2 related database tables which in simplified form look like this Product( product_id, name ) ProductSpecs( spec_id, product_id, name, value ) Foreign key is set via product_id field and ProductSpecs table has a unique constraint on (product_id, name) pair. Now in my ASP.NET MVC application when user edits product...

Need an overview of non-enterprise databases for .NET

For smaller websites which are view-only or require light online-editing, SQL Server 2008, Oracle, and MySQL are overkill. In the PHP world, I used SQLite quite a bit which is a e.g. 100K file holding hundreds of records which you speak to with standard SQL. In the .NET world, what options do we have, I've seen: SQL Server 2008 Expre...

Sql Server Ignore update errors

I have inherited a very old database that needs some data to be updated. Each row ha a column with a UniqueID that looks like C0042-45-39612. The last 3 numbers of the code are the category Id (in this case 612). I need to do an update that targets only certain categories and I'm using this SQL statement UPDATE WebbikesProducts SET Pr...

From what do sql parameters protect you?

Parameters are used to protect you from malicious user input. But if the parameter expects a string, is it possible to write input that will be interpreted as sql, so malicious users can use things like 'DROP', 'TRUNCATE', etc...? Are there differences in protection between parameters in asp, asp.net, java and others? See also: Are ...

SQL to L2S Translation Help

So here is the original query SELECT SUM(PickQty), SUM(ReqQty), AssignmentID, StopID FROM PickRequest GROUP BY AssignmentID, StopID in LINQ from a in dbReqs group a by new { a.AssignmentID, a.StopID } into pr select new { Assignment = pr.Key, StopID = pr.Select(s=> s.StopID), PickQty = pr.Sum(p=> p.PickedQty), Count = pr.Sum(c => c.Re...

Temporary Table Usage in SQL Server

This is a bit of an open question but I would really like to hear people opinions. I rarely make use of explicitly declared temporary tables (either table variables or regular #tmp tables) as I believe not doing so leads to more concise, readable and debuggable T-SQL. I also think that SQL can do a better job than I of making use of tem...