primary-key

Why is SQL Server not using Index for very similar datetime query?

萝らか妹 提交于 2020-01-03 17:06:47
问题 i have a table on SQL Server with about 1 million rows. It has an ID (PK), a status (int) and a datetime column. Also I've created an Index on the datetime column. Now I've found out an effect, which I don't understand. SELECT status FROM table WHERE dateTime BETWEEN '2010-01-01T00:00:00' AND '2010-01-02T12:00:00' This statement returns 3664 rows. It runs about 150ms and the execution plan shows that its doing an index seek with key lookup. Now, if I change it as following (just change the

MYSQL - What is a primary key?

限于喜欢 提交于 2020-01-03 16:57:25
问题 I'm in the process of learning Mysql, and I'm creating databases. So, after looking at several websites, the definition for a primary key is: The PRIMARY KEY constraint uniquely identifies each record in a database table. and is used like this: CREATE TABLE Persons ( P_Id int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(255), Address varchar(255), City varchar(255), PRIMARY KEY (P_Id) //primary key is on this line ) However, I still don't know what it's used for and why we need

MySQL ALTER TABLE on very large table - is it safe to run it?

孤街醉人 提交于 2020-01-03 07:21:08
问题 I have a MySQL database with a MyISAM table with 4 million rows. I update this table about once a week with about 2000 new rows. After updating, I then alter the table like this: ALTER TABLE x ORDER BY PK DESC I order the table by the primary key field in descending order. This has not given me any problems on my development machine (Windows with 3GB memory). Three times I have tried it successfully on the production Linux server (with 512MB RAM - and achieving the resulted sorted table in

SQL Unique Key Syntax

孤人 提交于 2020-01-02 05:39:05
问题 Very basic question; I'm very new to SQL and trying to decipher an example data base. In the below create table code, why does the define primary key syntax reference only the 'id' column once in parentheses but the unique key definition references the 'category' column twice? both before and within the parentheses. Seems like there is a simple answer to this but cant track one down: CREATE TABLE `categories` ( `id` SMALLINT NOT NULL AUTO_INCREMENT, `category` VARCHAR(30) NOT NULL, PRIMARY

Is there any benefit to creating and index on a primary key?

情到浓时终转凉″ 提交于 2020-01-01 16:51:08
问题 I checked this SO post: What's the difference between primary key, unique key, and index in MySQL? and found the statement: Also note that columns defined as primary keys or unique keys are automatically indexed in MySQL. Based on this, I have two questions: Am I safe in assuming that there is no performance benefit to creating an index on a primary key itself because the primary key, by design, is an index? Perhaps the more important question: If you are doing the classic example people cite

Should I define the primary key for each entity in Realm?

心不动则不痛 提交于 2019-12-31 12:13:13
问题 I have noticed that setting PK is not obligatory in Realm and simply can be omitted. But in documentation is stated that: Indexes are created automatically for primary key properties. And I'd like to clear up some questions: 1) What is the default value for PK is defined by Realm, if I don't assign it by myself. Is it hash or whatever ? (If I don't set PK and call [MyRealmObject primaryKey] it returns nil ) 2) If this implicit PK is indexed by default ? Should I worry about it, because if it

Generating a non-sequential ID/PK for a Django Model

僤鯓⒐⒋嵵緔 提交于 2019-12-31 08:45:06
问题 I'm on the cusp of starting work on a new webapp. Part of this will give users pages that they can customise in a one to many relationship. These pages naturally need to have unique URLs. Left to its own devices, Django would normally assign a standard AUTOINCREMENT ID to a model. While this works fantastically, it doesn't look great and it also makes pages very predictable (something that isn't desired in this case). Rather than 1, 2, 3, 4 I would like set-length, randomly generated

Custom keys for Google App Engine models (Python)

大憨熊 提交于 2019-12-31 08:40:07
问题 First off, I'm relatively new to Google App Engine, so I'm probably doing something silly. Say I've got a model Foo: class Foo(db.Model): name = db.StringProperty() I want to use name as a unique key for every Foo object. How is this done? When I want to get a specific Foo object, I currently query the datastore for all Foo objects with the target unique name, but queries are slow (plus it's a pain to ensure that name is unique when each new Foo is created). There's got to be a better way to

MERGE SQL Server Primary Key Violation

倖福魔咒の 提交于 2019-12-31 07:22:06
问题 is there any chance that I can execute the below sql statement successfully? Currently, I'm receiving Primary Key Violation on my query below. What I want is that, when the first record was inserted in the target table and if there is another same primary key that will be inserted, it should be execute an UPDATE not INSERT to avoid the primary key violation, but I don't know to write it in actual sql script. As of know, I only have the below script. // User-Defined Tabled Type DECLARE

Primary key column(s) (id) are not columns in this table ()

会有一股神秘感。 提交于 2019-12-31 01:49:09
问题 I am following the: http://framework.zend.com/manual/en/learning.quickstart.create-model.html. Keep hitting wall after wall of issues. My current one is the following error: An error occurred Application error Exception information: Message: Primary key column(s) (id) are not columns in this table () Stack trace: #0 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table\Abstract.php(982): Zend_Db_Table_Abstract->_setupPrimaryKey() #1 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table\Select