sql

Dropping all user tables/sequences in Oracle

As part of our build process and evolving database, I'm trying to create a script which will remove all of the tables and sequences for a user. I don't want to do recreate the user as this will require more permissions than allowed. My script creates a procedure to drop the tables/sequences, executes the procedure, and then drops the...

Are soft deletes a good idea?

Are soft deletes a good idea or a bad idea? Instead of actually deleting a record in your database, you would just flag it as "IsDeleted" = true, and upon recovery of the record you could just flag it as "False". Is this a good idea? EDIT: this might be a better idea??? what about physically deleting the record then moving it to a ext...

How to stop looking in a database after X rows are found?

I have a query to a database that returns a number X of results. I am looking to return a maximum of 10 results. Is there a way to do this without using LIMIT 0,9? I'll use LIMIT if I have to, but I'd rather use something else that will literally stop the searching, rather than look at all rows and then only return the top 10. ...

Purpose of SQLAlchemy over MySQLdb

Why do people use SQLAlchemy instead of MySQLdb? What advantages does it offer? ...

Aggregate SQL column values by time period

I have some numerical data that comes in every 5 minutes (i.e. 288 values per day, and quite a few days worth of data). I need to write a query that can return the sums of all values for each day. So currently the table looks like this: 03/30/2010 00:01:00 -- 553 03/30/2010 00:06:00 -- 558 03/30/2010 00:11:00 -- 565 ...

SQL query optimization

I have a problem with my SQL query that take time to get all records from database. Any body help me. Below is a sample of database: order(order_id, order_nm) customer(customer_id, customer_nm) orderDetail(orderDetail_id, order_id, orderDate, customer_id, Comment) I want to get latest customer and order detail information. Here is m...

need help with a simple SQL update statement.

There's a field with type of varchar. It actually stores a float point string. Like 2.0 , 12.0 , 34.5 , 67.50 ... What I need is a update statement that remove the ending zeros of fields like 2.0 , 12.0 , change them to their integer representation , that is 2 , 12 ...,and leave 3.45 , 67.50 unchanged . How should I do this ? I am using ...

MS-Access 2007 Time Online Report

I have the following data in my database: MemberID | DateTime ------------------------------------- 1 | 31/03/2010 3:45:49 PM 2 | 31/03/2010 3:55:29 PM 1 | 31/03/2010 4:45:49 PM Every time a user is authenticated or un-authenticated this log appears in the database. What I want to be able to do is total th...

Querying Access to form columns from records

At work we've got a roster that's historically been maintained in a huge Excel workbook. That's getting a bit fragile because of staff changes and such, so I'm trying to re-implement it robustly as an Access database. I've got a table of People (fields include name and some other attributes of people) and a table of Vacations -- each va...

Regular expression to validate whether the data contains numeric ( or empty is also valid)

Hi all, i have to validate the data contains numeric or not and if it is not numeric return 0 and if it is numeric or empty return 1. Below is my query i tried in SQL. SELECT dbo.Regex('^[0-9]','123') -- This is returning 1. SELECT dbo.Regex('^[0-9]','') -- this is not returning 1 but i want to return as 1 and i try to put space i...

Using CONNECT BY to get all parents and one child in Hierarchy through SQL query in Oracle

I was going through some previous posts on CONNECT BY usage. What I need to find is that what to do if I want to get all the parents (i.e, up to root) and just one child for a node, say 4. It seems Like I will have to use union of the following two:- SELECT * FROM hierarchy START WITH id = 4 CONNECT BY id = PRIOR parent union...

Oracle PL/SQL: Dump query result into file

Hi. I'm working on a pl sql stored procedure. What I need is to do a select, use a cursor and for every record build a string using values. At the end I need to write this into a file. I try to use dbms_output.put_line("toto") but the buffer size is to small because I have about 14 millions lines. I call my procedure from a unix ksh. I...

MySQL - Where - search string - MATCH.

Hi guys, Quick question. I'm in a bit of a rush but if someone could quickly point me in the right direction I would be very very happy. I have a field in the db, let's call it field_a which returns a string in the format "20,50,60,80" etc. I wish to do a query which will search in this field to see if 20 exists. Could I use MySQL MA...

Algorithm: Build a recommendation for movies you might like

I need help designing an algorithm for recommendations on movies. Every user in the system grades movies on a score between 1-100. Tables consist of: Table Movies ID Name Year Rating Runtime Table Con_MoviesToGenres MovieID GenreID Table Con_MovieToUser MovieID UserID Grade I'm trying to build a SELECT query t...

Protecting against transaction concurency (Transaction type; Transaction IsolationLevel)

Middle-tier component will execute the data access routines in application. The component will call several SQL Server stored procedures to perform database updates. All of these procedure calls run under the control of a single transaction. The code for the middle-tier will implement the following objects: SqlCommand comm = connection....

Date problem in MYSQL Query

Am looking for a query to sum values in a particular time duration say an year or a particular month in an year using MySQL syntax. Note that my transaction_date column stores daily amount transacted. Am example of a query that returns total sales in an year query would look something like this SELECT SUM(transaction_amount) WHERE tran...

Does COUNT(*) always return a result?

If I run a query such as: SELECT COUNT(*) as num FROM table WHERE x = 'y' Will it always return a result, even when the query doesn't match any record? Or do I need to validate and make sure a row is returned as the result? ...

SQL Server: How to trim all columns in a table

I have over 30 columns in my table (sql server 2008). Columns type are varchar(x). I know that in every column there is two extra spaces at the end of column value. How to use rtrim function for all columns and save this modification into this existing table? Edit: is there a way to do it using stored procedure or cursor where I don't h...

sql and linq query

Database has tables Photos and PhotoAlbums. I need a query that will select all albums and only one photo from each album. I need SQL and LINQ version of this query. Thanks in advance. ...

Getting a permission error when trying to connect to sql database

I have a sql server on a dedicated machine, running SQL 2008. I have the IP of the box, a database setup on it. I've built a small script that just does a connection test, and when I run it, I get the following error. Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture...