I have a table with ~30,000,000 rows that I need to iterate through, manipulate the data for each row individually, then save the data from the row to file on a local drive.
What is the most efficient way to loop through all the rows in the table using SQL for Oracle? I've been googling but can see no straightforward way of doing this....
I'd like to reduce actual database hits when working in django so I've created this artificial example to outline the problem. The model looks like this:
class Car(models.Model):
name = models.CharField(max_length=10)
user = models.ForeignKey(User)
In my view I want to do something like this:
def cartest(request):
cars = ...
If I have the following table & data to allow us to use the sort_index for sorting:
CREATE TABLE `foo` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`bar_id` INT(11) DEFAULT NULL,
`sort_index` INT(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `foo` (`bar_id`, `sort_index`) VALUES
(1,1),(1,2),(1,3),(1,4),
(2,1),(2,2),(2,3),(2...
I have decided in my table that I no longer want to record start and finish times, but rather just a start time and a duration in minutes. How can I update my table so that my new column has its values inserted based on the existing data? my attempt below yields the error:
You can't specify target table 'lesson' for update in FROM c...
I have developed a site using Asp.net C# 3.5 and now I feel that some of the pages are loading reeeaaally slooooow. I now need to start going through the website and try to find out whats making it so slow. But I don't know where to start, whats most likely causing the problem? Where do you usually start when trying to find out what is w...
I know that PreparedStatements avoid/prevent SQL Injection. How does it do that? Will the final form query that is constructed using PreparedStatements will be a string or otherwise?
...
I'm working on a simple voting system, using php and sqlite. I prebuild a whole scenario and tested it in the sqlite commandline, where it worked nicely.
But one query, which should return all possible answers of a poll and the users that voted for it, doesn't work anymore...
Tables:
CREATE TABLE polls (
question CHAR(200)
);
CREATE ...
I'm making a web application which also includes notification functionality - a user may get one or more notifications (messages) from the system or other users at any time.
When there are new (unread) messages they will be displayed to the user in a popup window. The messages will be short (most of the time one sentence each, and only ...
How do I view previous queries in SQL Server 2000 database
...
When I make a query...
is there any meaningful difference between using a find_by helper or not?
Are there any reasons I'm overlooking for opting for shorter lines of code when doing things like this?
Booking.find_all_by_user_id(1, :joins => :confirmation)
Booking.find(:all, :joins => :confirmation, :conditions => [ 'bookings.user_id...
I'm trying to write a query to work out how much commission that my client's company earns in a month as below
SELECT (rate * SUM(duration) / 180) as commission
FROM teacher, person, lesson
WHERE person.id = teacher.person_id
AND lesson.teacher = person.id
AND MONTH(start_time) = MONTH(NOW())
...
I have the following tables:
USERS table
id
username
email
password
status
FRIENDS table
id
user_id
friend_id
created
To find a users friends, I use:
SELECT f.friend_id,
u.username
FROM friends f
JOIN friends m ON m.user_id = f.friend_id
AND m.friend_id = f.user_id
JOIN users u ON u.user_id = f.fr...
I wrote this simple query statement:
INSERT INTO merchants
('firstName','lastName')
VALUES
('Bob','Smith')
Sounds very simple but I keep getting this error:
`#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''firstName','lastName' )
VALU...
I am new to SQL Server 2008 database development.
Here I have a master table named ‘Student’ and a child table named ‘Address’. The common column between these tables is ‘Student ID’.
My doubts are:
Do we need to put ‘Address Id’ in the ‘Address’ table and make it primary key? Is it mandatory? ( I won’t be using this ‘Address Id’ i...
This is a follow up to my previous question, in t-sql
SELECT SCOPE_IDENTITY()
returns a BIGINT, I did the following to get it to return an INT:
DECLARE @X INT
INSERT ...
SELECT @X = SCOPE_IDENTITY()
-- if i don't include the line below, it will return a BIGINT
SELECT @X
Why does it return a BIGINT unless I do SELECT @X at the...
HI
Could I fetch ALL the info from the user when he/she login and store it in sessions instead of having this piece of code on top of all pages to get username, email etc of the logged in user?
$userq = mysql_query("SELECT * FROM users WHERE id = {$_SESSION['id']}");
$auth_user = mysql_fetch_assoc($userq);
Login.PHP
$sql = mysql_qu...
I am trying to write T-sql script which will find "open" records for one table
Structure of data is following
Id (int PK) Ts (datetime) Art_id (int) Amount (float)
1 '2009-01-01' 1 1
2 '2009-01-05' 1 -1
3 '2009-01-10' 1 ...
Hi,
I am developing an early version of my site and before I create the production version, I'd like people's opinions on whether I'm going about things the right way. The main objective is to allow users to share playlists. I have the User table (ASP.NET Membership), Playlist table and a permission table. I'd like a user to create a...
Each time I launch the install, it launches the SQL Server Express 2008 panel instead of Management Studio why ?
...
Is it possible to alias a column name and then use that in a CASE statement? For example,
SELECT col1 as a, CASE WHEN a = 'test' THEN 'yes' END as value FROM table;
I am trying to alias the column because actually my CASE statement would be generated programmatically, and I want the column that the case statement uses to be specified ...