sql

How to load sql fixture in Django for User model?

Hi folks, Does anyone knows how to load initial data for auth.User using sql fixtures? For my models, I just got have a < modelname >.sql file in a folder named sql that syncdb does it's job beautifully. But I have no clue how to do it for the auth.User model. I've googled it, but with no success. Thanks in advance, Aldo ...

How to know when to use indexes and which type?

I've searched a bit and didn't see any similar question, so here goes. How do you know when to put an index in a table? How do you decide which columns to include in the index? When should a clustered index be used? Can an index ever slow down the performance of select statements? How many indexes is too many and how big of a table do...

Definitive country list for e-commerce applications

I am looking for a list of countries for use in the development of an e-commerce app including: Country Name, Country Code, Language, etc. While only the country name (and probably the country code) are really necessary, some of the other info may be nice (as long as there isn't too much!). I used to have a good list but I can't find ...

Multiple Selected Values of ListBox as Parameters to SELECT SQL Query

Hello, I want to pass the Multiple selected values from ListBox as parameters to my Select SQL Query. I am using VB.NET, how can I achieve this ?... ...

How do I get the highest sum per day for last X days?

Hi All, This is probably a easy one, but for the life of me I can't seem to figure it out. Here is my table: Date User Amount ---------- ----- ------ 01/01/2010 User1 2 01/01/2010 User2 2 01/01/2010 User1 4 01/01/2010 User2 1 01/02/2010 User2 2 01/02/2010 User1 2 01/02/2010 User2 4 01/02/2010...

Which is better practice: complex SQL statements or Recordset manipulation in Access VBA?

I'm doing some VBA development and I found creating SQLs quite efficient way of getting everything done (selecting and updating). But I got to this stage where my SQL statements contain complex Switches and WHERE conditions where I have another Selects to update appropriate records. Therefore, I create this SQLs and I simply run it via ...

How could I rewrite this loop of Django queries as a more efficient SQL query?

This is an inefficient way to update a denormalized field on an Player Django model. The field essentially stores the position of the player on the leaderboard, which is a requirement for a system we have for displaying "nearby" players to a given player. for position, player in enumerate(Player.objects.order_by('-score')): player.p...

How to use SQL Order By statement to sort results case insensitive?

I have a SQLite database that I am trying to sort by Alphabetical order. The problem is, SQLite doesn't seem to consider A=a during sorting, thus I get results like this: A B C T a b c g I want to get: A a b B C c g T What special SQL thing needs to be done that I don't know about? SELECT * FROM NOTES ORDER BY title ...

where can i find exercises to practice SQL statements?

do you know where i can find some practice SQL problems? where i can write select statements ...

Single MySQL query with count and sum

Hi there I have an SQL table that looks like this: CREATE TABLE IF NOT EXISTS `designerswave_article_visited` ( `article_visited_article_id` smallint(5) NOT NULL, `article_visited_user_id` smallint(5) NOT NULL, `article_user_rating` tinyint(1) DEFAULT NULL, UNIQUE KEY `article_id` (`article_visited_article_id`,`article_visited_...

FK constraints get enabled automatically + SQL

Hello We got a script to disable FK constraints by passing 'D' deactivate 'A' for activate. Once these are disabled, they get enabled back again after couple of hours or a day. What could be the reason ? Script is as below: CREATE PROCEDURE [dbo].[sp_DisableEnableForeignKeys] @PutFK CHAR(1) as DECLARE @IdFK integer DECLARE @Foreig...

what is the difference between WHERE and HAVING

Possible Duplicate: SQL: Whats the difference between HAVING and WHERE? i am learning sql syntax and i can't understand this. the second half of the question is a much more technical one. what is actually happening behind the scenes of the database between WHERE and HAVING? which one uses more resources? are they same algori...

Best books for SQL Server / database design.

I have some really good books for SQL Server, like: SQL Server 2008 Bible Pro SQL Server 2008 - Relational Database Design and Implementation SQL Server 2008 for Developers. Can you suggest/recommend some other titles, that may address other topics perhaps, that you found truly useful? ...

How to set conditional logic in SQL query in order to shuffle the precedence?

How to set conditional logic in SQL query in order to shuffle the precedence? For example if I have table with columns like "id", "name", "event_id" and I have distinct "event_id" like 180, 181, 270, 271 and I need to order in such a way that rows with "event_id" 270 will be at the top, then rows with "even_id" 271 and the rest of the d...

does AdventureWorks db have tutorials / exercises?

i downloaded and installed AdventureWorks db for sql server 2008. do u know if there are any exercises or tutorials for it? i want to practice my SQL select statements ...

last_update timestamp for every table?

Is it a good practice to have timestamps for the last row update in every table? Or should they only be set where really needed? How do I know where I will need an update timestamp later? For which kind of information do they make sense? ...

practicing WHERE and HAVING in SQL

here is the schema: here is the question: Point out the battles in which at least three ships from the same country took part. here is my answer: SELECT battles.name FROM battles, outcomes, ships, classes WHERE outcomes.ship = ships.name GROUP BY battles.name HAVING COUNT(classes.country) >...

Getting a count of each product for each ID

Table1 ID product 001 LG 001 Sony 001 LG 001 LG 001 Sony 001 BPL 001 BPL 001 Samsung 002 LG 002 BPL 002 LG ..., I want to take each product count for each personid. Expected Output ID BPL LG Samsung Sony 001 2 3 1 2 002 1 1 0 0 .., How to make a query of taking each product count for each personid. Need SQL Query Help. ...

UNION inside IF EXISTS statement not working

SELECT A, B, C FROM TUser UNION IF EXISTS(SELECT dataUserId FROM TUserData WHERE DataId = @dataId AND UserId = @userId) BEGIN SELECT @dataUserId = dataUserId FROM TUserData WHERE DataId = @dataId AND UserId = @userId SELECT A, B, C FROM TUser WHERE UserId = dataUserId END ...

Can I set a formula for a particular column in SQL?

Hello, I want to implement something like Col3 = Col2 + Col1 in SQL. This is somewhat similar to Excel, where every value in column 3 is sum of corresponding values from column 2 and column 1. ...