sql

SQL Server: Is SELECTing a literal value faster than SELECTing a field?

I've seen some people use EXISTS (SELECT 1 FROM ...) rather than EXISTS (SELECT id FROM ...) as an optimization--rather than looking up and returning a value, SQL Server can simply return the literal it was given. Is SELECT(1) always faster? (I can imagine this making a difference if the field is a large VARCHAR, but is there a perform...

Retrieving multiple rows into a listview control from an ODBC source works well for simple SELECTs with a statement attribute of SQL_SCROLLABLE. How do I do this with a UNION query?

I am retrieving multiple rows into a listview control from an ODBC source. For simple SELECTs it seems to work well with a statement attribute of SQL_SCROLLABLE. How do I do this with a UNION query (with two selects)? The most likely server will be MS SQL Server (probably 2005). The code is 'c' for the Win32 API. This code sets (wha...

What is the SQL command to return the field names of a table?

Say I have a table called myTable. What is the SQL command to return all of the field names of this table? If the answer is database specific then I need SQL Server right now but would be interested in seeing the solution for other database systems as well. ...

Can you turn off Visual Studio 2008 Query formatting?

Is it possible to turn off the query re-formatting that happens when you edit a query for a database in Visual Studio? (i.e. r-click a data source and select New Query) This is happening when we are writing sql queries against a sql compact 3.5 database. Its rather irritating when your carefully indented and formatted query is munged i...

MySQL Training videos

Hi were can I find training videos for MySQL ? ...

How to return multiple rows from the stored procedure? (Oracle PL/SQL)

I want to create a stored procedure with one argument which will return different sets of records depending on the argument. What is the way to do this? Can I call it from plain SQL? ...

How can I confirm a database is Oracle & what version it is using SQL?

I'm building an installer for an application. The user gets to select a datasource they have configured and nominate what type of database it is. I want to confirm that the database type is indeed Oracle, and if possible, what version of Oracle they are running by sending a SQL statement to the datasource. ...

How can I confirm a database is Postgres & what version it is using SQL?

I'm building an installer for an application. The user gets to select a datasource they have configured and nominate what type of database it is. I want to confirm that the database type is indeed Postgres, and if possible, what version of Postgres they are running by sending a SQL statement to the datasource. ...

What does a "WARNING: did not see LOP_CKPT_END" message mean on SQL Server 2005?

The above error message comes up just before SQL Server marks the database as "Suspect" and refuses to open it. Does anyone know what the message means and how to fix it? I think it's a matter of grabbing the backup, but would be nice if it was possible to recover the data. I've had a look at the kb article but there are no transactions...

Good books on Sybase ASE 15?

We need to get some good books on Sybase ASE 15 for our developers. The people in the team have previous experience with different SQL flavors (MS SQL, MySQL, Informix and Oracle) but no one worked with Sybase before. Therefore I am looking for two kinds of books: Book for developers on how to use Sybase for queries,sprocs, views etc....

SQL Server 2005 multiple database deployment/upgrading software suggestions

We've got a product which utilizes multiple SQL Server 2005 databases with triggers. We're looking for a sustainable solution for deploying and upgrading the database schemas on customer servers. Currently, we're using Red Gate's SQL Packager, which appears to be the wrong tool for this particular job. Not only does SQL Packager appear ...

`active' flag or not?

OK, so practically every database based application has to deal with "non-active" records. Either, soft-deletions or marking something as "to be ignored". I'm curious as to whether there are any radical alternatives thoughts on an `active' column (or a status column). For example, if I had a list of people CREATE TABLE people ( id ...

SQL strip text and convert to integer

Hi all, In my database (SQL 2005) I have a field which holds a comment but in the comment I have an id and I would like to strip out just the id, and IF possible convert it to an int: 'activation successful of id 1010101' The line above is the exact structure of the data in the db field. And no I don't want to do this in the code of ...

How would you get the Sql Command objects for a Given TableAdaptor and SqlDataAdaptor in C# (.NET 2.0)

I am creating a generic error handling / logging class for our applications. The goal is to log the exception info, info about the class and function (as well as parameters) and if relevant, the information about the System.Data.SqlClient.SqlCommand object. I would like to be able to handle passing in SqlCommands, TableAdaptors, and Sql...

Database safety: Intermediary "to_be_deleted" column/table?

Everyone has accidentally forgotten the WHERE clause on a DELETE query and blasted some un-backed up data once or twice. I was pondering that problem, and I was wondering if the solution I came up with is practical. What if, in place of actual DELETE queries, the application and maintenance scripts did something like: UPDATE foo SET t...

How can I get Datetime to display in military time in oracle?

I am running some queries to track down a problem with our backup logs and would like to display datetime fields in 24-hour military time. Is there a simple way to do this? I've tried googling and could find nothing. ...

SQL Question - Possibly Cursor/Join related?

Here is my situation: Table one contains a set of data that uses an id for an unique identifier. This table has a one to many relationship with about 6 other tables such that. Given Table 1 with Id of 001: Table 2 might have 3 rows with foreign key: 001 Table 3 might have 12 rows with foreign key: 001 Table 4 might have 0 rows with fo...

Why can't I open this table in SQL Server Management Studio?

I created a couple of tables procedurally via C# named something like [MyTableOneCustom0] and [MyTableTwoCustom0]. When I try to return all of the values from these tables via "Open Table" in MS SQL Server Management Studio, I receive the following error: Error Source: Microsoft.VisualStudio.DataTools Error Message: Exception ...

how do I query multiple SQL tables for a specific key-value pair?

Situation: A PHP application with multiple installable modules creates a new table in database for each, in the style of mod_A, mod_B, mod_C etc. Each has the column section_id. Now, I am looking for all entries for a specific section_id, and I'm hoping there's another way besides "Select * from mod_a, mod_b, mod_c ... mod_xyzzy where s...

SQL Query Help: Transforming Dates In A Non-Trivial Way

I have a table with a "Date" column, and I would like to do a query that does the following: If the date is a Monday, Tuesday, Wednesday, or Thursday, the displayed date should be shifted up by 1 day, as in DATEADD(day, 1, [Date]) On the other hand, if it is a Friday, the displayed date should be incremented by 3 days (i.e. so it becom...