sql

What can cause an Oracle ROWID to change?

AFAIK ROWID in Oracle represents physical location of a record in appropriate datafile. In which cases ROWID of a record may change ? The one known to me is UPDATE on partitioned table that "moves" the record to another partition. Are there another cases ? Most of our DBs are Oracle 10. ...

How can i use PHP to show datetime without seconds

How can i change ex. 2009-01-14 06:38:18 to 2009-01-14 06:38? the column type is DATETIME. i dont wanna use SELECT DATE_FORMAT how could i do it with php? date("M-d-Y H:i", $userow['regdate']) gives: Strict Standards: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting,...

.Net Function call in SQL 2005

I am getting the following error when I execute a .Net Function in SQL 2005, any ideas? Msg 6522, Level 16, State 2, Line 1 A .NET Framework error occurred during execution of user defined routine or aggregate 'Function1': System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, Sy...

"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...

Postgresql: how to create table only if it does not already exist?

I am totally new to postgresql. How can I do a condition to create a table only if it does not already exists? Code example appreciated. ...

SQL Sub-Query vs Join Confusion

I have a database which is in Access (you can get it link text). If I run SELECT DISTINCT Spl.Spl_No, Spl.Spl_Name FROM Spl INNER JOIN Del ON Spl.Spl_No = Del.Spl_No WHERE Del.Item_Name <> 'Compass' It provides the names of the suppliers that have never delivered a compass. However you can supposedly do this with a sub-query. So f...

How do I find duplicate entries in a database table?

The following query will display all Dewey Decimal numbers that have been duplicated in the "book" table: SELECT dewey_number, COUNT(dewey_number) AS NumOccurrences FROM book GROUP BY dewey_number HAVING ( COUNT(dewey_number) > 1 ) However, what I'd like to do is have my query display the name of the authors associated with the dupl...

How to find WITH RECOMPILE metadata in SQL Server (2005)?

How do you find which SPs are declared WITH RECOMPILE, either in INFORMATION_SCHEMA, sys.objects or some other metadata? (I'm adding some code to my system health monitoring and want to warn on ones which are declared that way where it is not justifiable.) Note: I'm not looking for general text search for 'WITH RECOMPILE' - I can alrea...

SQL INSERT, Force Truncate Field

I have input data containing some "rogue" fields that are longer than the corresponding database field. This causes my import script, which uses SQL INSERT statements to fall over with a warning: Msg 8152, Level 16, State 13, Line 2 String or binary data would be truncated. How can I force truncation of these fields and enable my scri...

When or why would you use a right outer join instead of left?

I think the title says it all. Wikipedia states: "In practice, explicit right outer joins are rarely used, since they can always be replaced with left outer joins and provide no additional functionality." Can anyone provide a situation where they have preferred to use the RIGHT notation, and why? I can't think of a reason to ever use i...

Formula parsing / evaluation routine or library with generic DLookup functionality

I am writing a .Net application where I must support user-defined formulas that can perform basic mathematics, as well as accessing data from any arbitrary table in the database. I have the math part working, using JScript Eval(). What I haven't decided on is what a nice way is to do the generic table lookups. For example, I may have a...

MySQL: Migrating Queries from v4 to v5

When migrating a project from MySQL 4 to MySQL 5, what are the primary things I need to address in order to ensure queries remain compatible? In general things should be fine, but I know that some things that worked implicitly in MySQL 4 queries have to be defined explicitly in MySQL 5 (but I can't for the life of me remember what exaxt...

SQL Server 2000 - What really is the "Actual Number of Rows" ?

Hello, I have an SQL Server 2000 query which performs an clustered index scan and displays a very high number of rows. For a table where I have 260.000 records, the actual number of rows displayed in the plan execution is ... 34.000.000. Does this makes sense? What am I misunderstanding? Thanks. ...

Help with TSQL - a way to get the value in the Nth column of a row?

I hope to find a way to get the value in the Nth column of a dataset. Thus, for N = 6 I want SELECT (Column6Value) from MyTable where MyTable.RowID = 14 Is there a way to do this in TSQL as implemented in SQL Server 2005? Thanks. ...

How to get more than 1000 items in HSQLDB in CASE WHEN statement?

I'm running the following query in Hypersonic DB (HSQLDB): SELECT (CASE foo WHEN 'a' THEN 'bar' WHEN 'b' THEN 'biz' .... ELSE 'fin' END ) FROM MyTable LIMIT 1 When the number of "WHEN" clauses exceeds about 1000, I get a Java StackOverflowError thrown by the JDBC driver in org.hsqldb.jdbc.Util.sqlException(). Here's the reall...

How can you upgrade a datatype from a 32-bit Integer to a 64-bit Integer in SQL for all foreign keys?

For basically every SQL database out there, how would you upgrade your data types and have all the foreign keys linked to that data type be upgraded? For example, let's say I have ScientificResult is a 32-bit integer. Now I want ScientifcResult to be a 64-bit integer. ScientificResult is also a foreign key for a few other tables but...

Checklist towards optimal performance in a database import application

I am facing an application designed to import huge amounts of data into a Microsoft SQL Server 2000 database. The application seems to take an awful long time to complete and I suspect the application design is flawed. Someone asked me to dig into the application to find and fix serious bottlenecks, if any. I would like a structured appr...

How do I represent my joins in Relational Algebra?

I am new to relational algebra and for my assignment I have to create two. I have written out the problem I have faced in SQL but I am unsure of how to represent such joins in relational algebra. Any help/pointers would be greatly appreciated. SELECT ps.FirstName AS StudentFirstName, ps.LastName AS StudentLastName, pst.FirstName AS Staf...

Transposing a table with SQL

Hi there, I have a SQL table like so PV Area CouterParty 851 M010 Name1 561 M011 Name2 869 M012 Name3 ... And I need to transpost it, using T-SQL (not reporting services or anything else), so that it looks like this: CounterParty M010 M011 M012 .... Name1 851 Name2 561 Name...

Index a sum column

Is creating an index for a column that is being summed is faster than no index? ...