primary-key

Don't use deleted primary keys

风格不统一 提交于 2019-12-02 00:09:53
Insert id 1 and 2. Remove id 2. Insert new row, it gets id 2 instead of 3. How do I change this? I don't want to reuse primary keys. import sqlite3, os os.remove('mydatabase.db') conn = sqlite3.connect("mydatabase.db") # or use :memory: to put it in RAM cursor = conn.cursor() # create a table cursor.execute("CREATE TABLE if not exists albums (id INTEGER PRIMARY KEY NOT NULL, title text, artist text, release_date text, publisher text, media_type text)") cursor.execute("CREATE TABLE if not exists anti (id INTEGER, title text, artist text, release_date text, publisher text, media_type text)")

Using Hibernate Get with Multi-Column Primary Key

好久不见. 提交于 2019-12-01 23:23:47
Say I have a class that looks like this: public class MyClass { @Id @Column(name = "ID") private long Id; } I can use a hibernate session to do a get or load on the class like this: MyClass a = (MyClass)session.get(MyClass.class, new Long(100)); However, assume I have a class with multiple columns as the primary key: public MyJoinClass implements Serializable { private static final long serialVersionUID = -5L; @Id @Column(name = "ID") private long id; @Id @Column(name = "EMAIL_ADDRESS_ID") private long emailAddressId; } Is it possible to use get or load with such a class? Koitoer Try to use

Possible to condense primary key/serial?

本小妞迷上赌 提交于 2019-12-01 23:19:57
I have a database where everything is linked with foreign keys, so the Postgres knows exactly how the database is layed out.. Well, Lets say I have Table1 and Table2. Table1 has 3 fields. RID, table2_rid,data So table1.table2_rid references table2.RID and this is expressed with a foreign key. In both the RID field is the primary key and is a serial type. What I would like to know is how to "condense" the primary keys? Like say you add 5 records and deleted record number 3. Your primary keys would look like 1 2 4 5 Well, how do I get to update everywhere so that the primary key(and

iPhone Core Data Fetch Primary Key

给你一囗甜甜゛ 提交于 2019-12-01 23:02:10
I am developing an application that uses CoreData. So in .sqlite file, It manages Primary key itself. Primary key attribute name is Z_PK . My problem is that, I wants data from my table sorted ascending by primary key. I'm using that code NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"_PK" ascending:YES]; [fetchRequest setSortDescriptors:[NSArray arrayWithObject:sort]]; [sort release]; But it's not working. when I'm using "title" insted of "_PK", It's working Fine NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"title" ascending:YES]; [fetchRequest

On Duplicate Key not working in SQLite

流过昼夜 提交于 2019-12-01 22:32:41
问题 In my table, id is the primary key, but this code not working in sqlite3: insert into text (id,text) VALUES(150574,'Hello') ON DUPLICATE KEY UPDATE 'text' = 'good' Please help me. 回答1: INSERT .... ON DUPLICATE don't exist in SqLite. But you can use INSERT OR REPLACE to achieve the effect like the following. INSERT OR REPLACE INTO text (id, text) VALUES (150574, (SELECT CASE WHEN exists(SELECT 1 FROM text WHERE id=150574) THEN 'good' ELSE 'Hello' END ) ) Ref: http://www.sqlite.org/lang_insert

Primary key value after insertion of row in SQL Server 2005

旧城冷巷雨未停 提交于 2019-12-01 22:18:07
In SQL Server 2005 I am inserting a row into a table using a stored procedure and I want to fetch the new primary key value just after inserting that row. I am using following approach to get primary key value after insertion row Create Proc Sp_Test @testEmail varchar(20)=null,-- Should be Unique @testName varchar(20)=null -- Should be Unique as begin insert into tableTest (testUserEmail,testUserName)values (@testValue,@testName) select MAX(ID) from tableTest --ID is Primary Key --or select ID from tableTest where testUserEmail =@testValue and testUserName = @testName --or select SCOPE

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

南楼画角 提交于 2019-12-01 22:08:58
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.php(100): Zend_Db_Table_Abstract->info() #2 C:\wamp\www\zendtest\quickstart\library\Zend\Db\Table

does it worth switching a PRIMARY KEY from the type NVARCHAR to the type INT?

☆樱花仙子☆ 提交于 2019-12-01 21:34:59
问题 On our SQL SERVER 2008 R2 database we have an COUNTRIES referential table that contains countries. The PRIMARY KEY is a nvarchar column: create table COUNTRIES( COUNTRY_ID nvarchar(50) PRIMARY KEY, ... other columns ) The primary key contains values like 'FR', 'GER', 'US', 'UK', etc. This table contains max. 20 rows. We also have a SALES table containing sales data: create table SALES( ID int PRIMARY KEY COUNTRY_ID nvarchar(50), PRODUCT_ID int, DATE datetime, UNITS decimal(18,2) ... other

Identity-like column but based on Group By criteria

ε祈祈猫儿з 提交于 2019-12-01 20:38:50
问题 In my SQL Server 2012 database, I'm creating a "Tasks" table that will have a compound primary key composed of three fields: Issue_ID [int] NOT NULL, Issue_Sub_ID [int] NOT NULL, Task_ID [int] NOT NULL Issue_ID and Issue_Sub_ID are foreign keys to other tables. In the table I'm creating, there can be many tasks associated with each Issue_ID / Issue_Sub_ID combination. What I would like to do is establish a default value for the Task_ID column, similar to if I used IDENTITY(1,1) , but that

What happens when I drop a clustered primary key in SQL 2005

微笑、不失礼 提交于 2019-12-01 19:25:21
I've a PK constraint - a clustered index on two columns - which I am in the process of dropping. The command is still running after an hour. I would have thought that as I am just removing a constraint the operation would be nearly instantaneous. Can someone explain to me what is actually happening under the hood when I drop the PK? Clustered index is not "just a constraint", it's a storage method. When you drop it, your data are being reordered from clustered storage to heap storage Other indexes are being updated to refer to RID 's instead of PRIMARY KEY values. The clustered index is the