sql

Get total amount of rows from different table with matching ID

For my first table i have questions like this: qid | question | date 1 blah 22-05-2009 and then i have the table comments cid | qid 1 1 2 1 3 1 so then in my questions table i could have an added column which had total_comments which would be three Ive tryed using this code SELECT questions.qid, questi...

Good table editor for MS SQL Server?

I have MS SQL Management Studio for editing table data, and it is doesn't have a good usability. I need to edit some hundred rows like in Excel, being able to order columns to easy editing process (SQL Mgmt only has 'Open table' feature, without ordering columns, updates diferent than that is only possible using UPDATE SQL code). LinqPa...

How do I find the last time that a PostgreSQL database has been updated?

I am working with a postgreSQL database that gets updated in batches. I need to know when the last time that the database (or a table in the database)has been updated or modified, either will do. I saw that someone on the postgeSQL forum had suggested that to use logging and query your logs for the time. This will not work for me as t...

Can I use SQL to find missing numbers in the example table I give below?

Let's say I have the following table with three columns: id | start_block | end_block ----------------------------- 01 | 00000000001 | 00000000005 02 | 00000000006 | 00000000011 03 | 00000000012 | 00000000018 04 | 00000000025 | 00000000031 05 | 00000000032 | 00000000043 Each row was a "Start Block" and an "End Block". If the data was...

VS2008 and SQL Express 2008

How do I make the SQL Express 2008 the default for VS2008 instead of SQL Express 2005? ...

How would this SQL query be evaluated by the query engine?

Hi I was playing around with SQL Queries and this one came to my mind - select x,y from table T. Here x and y can be arithmetic expressions like 2.0/5.0 OR 1+2, the result has the number of rows of table T, with the first column having value 2.0/5.0 i.e. 0.444444 and the second column having value 3. I am curious to know as to how thi...

Improving my data access layer

I am putting some heavy though into re-writing the data access layer in my software(If you could even call it that). This was really my first project that uses, and things were done in an improper manner. In my project all of the data that is being pulled is being stored in an arraylist. some of the data is converted from the arraylist...

Log changes to database table with trigger

I am looking for a good way to log changes that occur on a particular set of tables in my SQL Server 2005 database. I believe the best way to do this is through a trigger that get's executed on updates and deletes. Is there anyway to grab the actual statement that is being ran? Once I have the statement I can easily log it someplace else...

Is there a faster way to get a random record from a MySQL table through ActiveRecord?

In a Rails application, I'm using this to get a random row from a MySQL table: contact = Contact.find(:all, :limit => 1, :order => 'RAND()')[0] Even though the table only has about 20,000 rows it takes a couple seconds. Does anyone know of a faster way? Update Also tried just running the SQL in the console... SELECT * FROM `conta...

Is SQL or even TSQL Turing Complete?

This came up at the office today. I have no plans of doing such a thing, but theoretically could you write a compiler in SQL? At first glance it appears to me to be turing complete, though extremely cumbersome for many classes of problems. If it is not turing complete, what would it require to become so? Note: I have no desire to d...

SQL read data from table in vb

I'm trying to get a single field back from the data. (I am searching by a primary key so I should get 0 or 1 answer). Please help. The table that I am querying has one entry with user = someone, input to several columns with the ans column having "a good answer" Code: Dim reader As SqlDataReader Dim par As SqlParameter Dim result As ...

MYSQL case sensitive search for utf8_bin field

I created a table and set the collation to utf8 in order to be able to add a unique index to a field. Now I need to do case insensitive searches, but when I performed some queries with the collate keyword and I got: mysql> select * from page where pageTitle="Something" Collate utf8_general_ci; ERROR 1253 (42000): COLLATION 'utf8_gener...

How to calculate the smallest period of time between consecutive events?

Lets say that I have a table with a timestamp column full of records and I want to calculate the smallest time difference between two consecutive records using only one query. Maybe a table like... CREATE TABLE `temperatures` ( `temperature` double, `time` timestamp DEFAULT CURRENT_TIMESTAMP ); ...

LINQ to SQL updates

Does any one have some idea on how to run the following statement with LINQ? UPDATE FileEntity SET DateDeleted = GETDATE() WHERE ID IN (1,2,3) I've come to both love and hate LINQ, but so far there's been little that hasn't worked out well. The obvious solution which I want to avoid is to enumerate all file entities and set them manua...

MySQL with 2 LEFT JOINs on the same table

Hi everyone. I'm trying to run this query: SELECT Destaque.destaque, Noticia.id, Noticia.antetitulo, Noticia.titulo, Noticia.lead, Noticia.legenda, Noticia.publicacao, Seccao.descricao, Album.pasta, Foto.ficheiro, Foto.descricao, Cronista.nome, Cronista.profissao, Cronista.ficheiro, AudioFile.*, AudioCollection.*, Video...

SQL SHA1 inside WHERE

Hello, In my program, we store a user's IP address in a record. When we display a list of records to a user, we don't want to give away the other user's IP, so we SHA1 hash it. Then, when the user clicks on a record, it goes to a URL like this: http://www.example.com/allrecordsbyipaddress.php?ipaddress=SHA1HASHOFTHEIPADDRESS Now, I ne...

How to use variables in SQL statement in Python?

Ok so I'm not that experienced in Python. I have the following Python code: cursor.execute("INSERT INTO table VALUES var1, var2, var3,") where var1 is an integer, var2 & var3 are strings. How can I write the variable names without python including them as part of the query text? ...

If I'm querying a database, how can I get the 5th row back from a given row?

If I have a row id and I want the 5th row back from that row how would I do this? Normally I could just go rowId - 5 and that would be the id of the 5th row back... However, I need to account for if a row has been deleted, this would mean that, for example 39, 40, 41, 42, 43, 44, 45 if rowId was 45, then I would get rowId of 40 fo...

MySQL Query, Join, and Myself, or how I always take the hard way through.

I'm creating a small forum. Attempting to run SElECT... JOIN... query too pick up information on the individual posts, plus the last reply (if any). As part of my desire to do everything the hard way, this covers five tables (only columns revelant to this issue are being stated) commentInfo referenceID | referenceType | authorID | ...

Indexing a 'non guessable' key for quick retrieval?

I'm not fully getting all i want from Google analytics so I'm making my own simple tracking system to fill in some of the gaps. I have a session key that I send to the client as a cookie. This is a GUID. I also have a surrogate IDENTITY int column. I will frequently have to access the session row to make updates to it during the life o...