New answers tagged

3

To answer your question directly: No. Using floats for a primary key is not a good idea. Why? Because floats can run into problems with rounding and precision (Is 1.20 the same as 1.2? Because mathematically it is.) Personally I would create a primary key on a single field. Preferably an integer. Integers are typically more efficient than floats and there ...


2

To be fair I know nothing of sqlite but treating it strictly as a design problem I would have <storeid1, storeid2, distance> With a primary key on a combination of the three. The table isn't going to change very often (only when new stores arrive) and the distance between two stores will never change so you don't have to worry about inserts a great ...


0

You cannot get it automated via FOREIGN KEY. Plan A: Use a TRIGGER. Plan B: Use INSERT .. ON DUPLICATE KEY UPDATE ...


2

Indexes with the columns in the order given: actions: INDEX(user_id_to, user_id_from) -- 'covers' first query actions: INDEX(user_id_to, counter) -- may subsume ORDER BY and LIMIT in 3nd query Either index will be useful for 2nd query. DROP KEY user_id_to (user_id_to) as redundant when you add my two suggestions. For various reasons, it may be better to ...


13

Unless you explicitly state a desired order using an ORDER BY clause you can not guarantee the order that data will be presented in response to a query. Without an ORDER BY clause the engine is free to present data to you in any order it finds most convenient at the time, which can mean a different order for the same query you ran earlier. If there is a ...


0

The first part of the solution was – as I said in the question – to convert the primary key index into a non-primary index by turning Primary off (and leaving Unique on) in the Indexes window. An alternative means for creating such an index, as suggested by @mpag, is via SQL: CREATE UNIQUE INDEX uidx_engagement ON Engagement (Emp_id, Year, ...


0

You may use DESC in an index declaration, but it is ignored. (The PRIMARY KEY is an index.) You must say DESC in the ORDER BY clause if you want the resultset sorted that way.


-4

Foreign key it is a relationship between the two tables,Primary key is a not allow the duplicates and nulls.



Top 50 recent answers are included