sql

AddWithValue without DBType causing queries to run slowly

I've been using cmd.Parameters.AddWithValue, and not specifying a DBType (int, varchar,...) to run queries. After looking at SQL Profiler, it seems that queries run with this method run a lot slower than when you specify the data type. To give you an idea of how much slower it is, here's an example. The query is a simple lookup on a...

SQL Server 2005 deadlock on key

I have a table with a clustered primary key index on a uniqueidentifier column. I have a procedure that runs the following psuedo functions: begin transaction read from table 1 insert into table 2 update table 1 with pointer to table 2 record commit transaction This all works fine until the same procedure is executed concurrently from...

PHP: multiple SQL queries in one mysql_query statement

So I have an SQL dump file that needs to be loaded using mysql_query(). Unfortunately, it's not possible to execute multiple queries with it. -> It cannot be assumed that the mysql command-line client (mysql --help) is installed -- for loading the SQL file directly -> It cannot be assumed that the mysqli extension is installed /* cont...

combining and joining two tables with different no. of columns and same column name

I tried to combined tables which is fus_shift and root table into a new table which is final table but it outputs like "ERROR at line 2: ORA-01789: query block has incorrect number of result columns". I tried also joining table as my alternative but it also outputs "ERROR at line 3: ORA-00918: column ambiguously defined". Is there anoth...

SQL query of multi-member file on AS400

On AS400 in interactive SQL in a 5250 session, select * from myfile returns rows from one member only when myfile has more than one member. How can I get rows from a specific member? Important: in the end I'd like to do this over JDBC with jt400 so really I want a solution that'll work there. Thanks. ...

How to query for 10 most recent items or items from last month, whichever is more?

On my blog, I want to display the all the posts from the last month. But if that is less than 10 posts, I want to show the ten most recent posts (in other words, there should never be less than 10 posts on the front page). I am wondering if there is a way to do this in a single query? Currently, I first run this query: select count(*...

What are the most common SQL anti-patterns?

All of us who work with relational databases have learned (or are learning) that SQL is different. Eliciting the desired results, and doing so efficiently, involves a tedious process partly characterized by learning unfamiliar paradigms, and finding out that some of our most familiar programming patterns don't work here. What are the c...

LINQ for Java tool

Would a LINQ for java be a useful tool? I have been working on a tool that will allow a Java object to map to a row in a database. Would this be useful for Java programmers? What features would be useful? ...

Should I delete or disable a row in a relational database?

In a brand new program where space isn't really that big a deal, is it better to delete a row or to disable a row by let's say a boolean "Disabled" and have the program just ignore it? For example, if I wanted to remove a user from a program. ...

What are the advantages to each approach for mapping application end users to database users?

There seems to be three common approaches for mapping an application end user to a database user. One to One Mapping: Each Application user (bob, nancy and fred) also get a corresponding database user account (bob nancy and fred). N to M mapping: Each application user is mapped to a database user that represents their role. bob and...

SQL Statement Help - Select list of CustomerID, OrderDate with the most records in a table.

I'll be using the AdventureWorks Database to illustrate my problem. I need to show for a particular customer a list of OrderDate with the most Orders. My intial attempt was as follows: SELECT CustomerID, OrderDate, COUNT(1) Cnt FROM Sales.SalesOrderHeader WHERE CustomerID = 11300 GROUP BY CustomerID, OrderDate ORDER BY Cnt DESC This...

SmallDateTime Default Format Problem in SQLSERVER 2005

Hi, i am new in SqlServer.When i insert 07.12.2008 12:34:00 into my smalldatetime type column,it is inserted but when i select it in query analyzer,i see it as 2008-12-07 12:34:00.How can i change default format of that column? ...

How to transform rows to columns

I have a simple problem when querying the SQL Server 2005 database. I have tables called Customer and Products (1->M). One customer has most 2 products. Instead of output as CustomerName, ProductName ... I like to output as CustomerName, Product1Name, Product2Name ... Could anybody help me? Thanks! ...

dd.mm.yyyy hh:mm format in Sql Server

Hi, I looked at SQL Server dateformat codes but I couldn't find dd.mm.yyyy hh:mm format in the list. German Date Format(Code is 4) works for me but it doesn't contain hh:mm. Does someone know this format's code? ...

Updating multiple rows Linq vs SQL

Some time ago I wrote a piece of code to update multiple rows in a database table. The code was like this var db = new MyDataContext(); db.Execute("UPDATE Details SET IsActive = 0 WHERE MasterId = 1"); Then the other day when I got the latest version of the file I saw that somebody changed the code to something like this var details ...

Thoughts on Entity Framework

I was wondering what people thought about the decision to support Entity Framework over LINQ-to-SQL? I have an application I'm developing originally in LINQ-to-SQL. I found it the perfect solution for our application. While attempting to port to Entity Framework I was surprised how rough it was. IMHO, not even close to being ready f...

How to automate SQL backup on a shared hosted server?

I'm using a hosting service which allows me to backup my SQL 2008 database and download the BAK file via a web interface only--and I have access to the database via Management Studio. I can execute the backup command from Management Studio,but I don't have rights to the path where the backups are located. Is there any way via SQL or scri...

Another LINQ Pivot Problem - Convert SQL Script to LINQ

There are a few questions on SO already regarding LINQ pivots and while a couple of them outline my exact problem, I can't successfully translate them to a working solution. I feel that this is mostly due to a join in my tables. So for the benefit of all the LINQ junkies out there who love a problem, here's another puzzle for you to wo...

AS400 style naming over JDBC

Is there any way I can use AS400 style library/file style naming over JDBC with jt400? I want to be able to run queries like: SELECT * FROM MYLIBRARY/MYFILE Thanks ...

Can a sql server table have two identity columns?

I need to have one column as the primary key and another to auto increment an order number field. Is this possible? EDIT: I think I'll just use a composite number as the order number. Thanks anyways. ...