primary-key

How to set primary key with auto increment in MongoDB? [duplicate]

女生的网名这么多〃 提交于 2019-12-03 22:34:57
This question already has answers here : Closed 5 years ago . How do you implement an auto-incrementing primary ID in MongoDB? (7 answers) How to set primary key with auto increment in MongoDB ? Normally MongoDB generates ObjectID. I wanna use my own auto increment primary key like MySQL. Examples would be appreciated :) I blogged about this here: http://www.alexjamesbrown.com/blog/development/mongodb-incremental-ids/ I also started a int id generator for the C# driver: https://github.com/alexjamesbrown/MongDBIntIdGenerator However, incrementing ID's won't scale effectively. $db->execute(

How to save a UUID as binary(16) in java

江枫思渺然 提交于 2019-12-03 17:13:26
I have a table TestTable with columns ID as binary(16) and name as varchar(50) I've been trying to store an ordered UUID as PK like in this article Store UUID in an optimized way I see the UUID is saved in database as HEX (blob) So I want to save this ID from java but I am getting this error Data truncation: Data too long for column 'ID' at row 1 I am currently using the library sql2o to interact with mysql So basically this is my code String suuid = UUID.randomUUID().toString(); String partial_id = suuid.substring(14,18) + suuid.substring(9, 13) + suuid.substring(0, 8) + suuid.substring(19,

Why can't you use SQLite ROWID as a Primary key?

心不动则不痛 提交于 2019-12-03 16:34:33
问题 This does not execute: create table TestTable (name text, age integer, primary key (ROWID)) The error message is: 11-23 11:05:05.298: ERROR/Database(31335): Failure 1 (table TestTable has no column named ROWID) on 0x2ab378 when preparing 'create table TestTable (name text, age integer, primary key (ROWID))'. However, after the TestTable is created, this prepares and executes just fine: create table TestTable (name text, age integer); insert into TestTable (name, age) values ('Styler', 27);

alter table drop column syntax error using sqlite

大城市里の小女人 提交于 2019-12-03 15:54:14
问题 This is the schema of my table: create table LPCG(ID integer primary key, PCG text, Desc text, test text); I wish to drop the column "test", and hence use the command: alter table LPCG drop column test; This is the error message I get: Error: near "drop": syntax error Can someone please help me correct my error? An additional question is: I understand that ID is the primary key attribute. Would I be able to drop that column? If not, is there a workaround which anyone has used? Thanks in

multicolumn primary keys in rails

孤街醉人 提交于 2019-12-03 14:38:34
I'm trying to migrate a desktop application to rails (also dealing with quite old fashioned existing database). The problem is that I don't have a unique ID in one column, but it's three columns of a table that guarantee uniqueness of a record. Given I have three tables: authors author_name, author_letter, author_nr1, author_nr2 ... titles titel_nr, titel_name, ... author_titles titel_nr, author_letter, author_nr1, author_nr2 The "primary key" of authors consists of author_letter, author_nr1, author_nr2 here. So do I need sort of a multicolumn primary key here to have rails associations

How do I retroactively add a primary key to my table in rails?

ⅰ亾dé卋堺 提交于 2019-12-03 14:36:01
问题 I've created a table without a primary key (:id => false), but now it has come back to bite my ass. My app is already in production and I can't just drop it and recreate another one. Is there a way to run a migration to add another auto increment primary key column to my table? 回答1: The command to add a primary key in a migration is: add_column :my_table, :id, :primary_key However, the wording of your question suggests that your table already has an auto-increment column. Unless I'm mistaken,

Get all employee who directly or indirectly reports to an employee, with hierarchy level no

故事扮演 提交于 2019-12-03 13:48:54
问题 I have a Employee table like emp_id bigint, reports_to bigint, emp_name varchar(20), Constraint [PK_Emp] Primary key (emp_id), Constraint [FK_Emp] Foreign key (reports_to) references [MSS].[dbo].[Emp]([emp_id]) emp_id reports_to emp_name ------ ------ -------------- 1 null Sumanta 2 1 Arpita 3 null Pradip 4 1 Sujon 5 2 Arpan 6 5 Jayanti I want to get all the employees that directly or indirectly reports to Sumanta or emp_id(1), and with hierarchy level, like this: emp_id hierarchy_level emp

Why do we need to use Foreign Keys? [duplicate]

非 Y 不嫁゛ 提交于 2019-12-03 13:39:27
Possible Duplicate: Should I use foreign keys? Ok, let's assume we have two tables, users and comments . In comments we have a column comment_made_by_user_id and it means which user typed that particular comment. Why do we need to specify it as a foreign key? If we don't do that, it will still work. We specify primary keys, because it makes queries faster as far as I know (we need to search only for one row while when we don't have a primary key/index, we have to go through all rows). Is it just a good coding practise? When you use foreign keys you get: Data integrity faster queries. users:

JPA: is @PrimaryKeyJoinColumn(…) the same as @JoinColumn(…, insertable = ?, updatable = ?)?

社会主义新天地 提交于 2019-12-03 13:05:53
问题 Can you derive from the JPA spec, if @PrimaryKeyJoinColumn(...) , which doesn't have the insertable and updatable parameters, is the same as @JoinColumn(..., insertable = false, updatable = false) or @JoinColumn(..., insertable = true, updatable = true) when used on regular (non-inheritance) associations? Should they be interchangable? What are the insertable and updatable properties set to? Are they set to anything at all? Note, I'm only targeting the read-only attribute that both (seem to)

Can a table have two foreign keys?

我的未来我决定 提交于 2019-12-03 11:13:09
问题 I have the following tables (Primary key in bold . Foreign key in Italic ) Customer table ID---Name ---Balance--- Account_Name --- Account_Type Account Category table Account_Type ----Balance Customer Detail table Account_Name ---First_Name----Last_Name---Address Can I have two foreign keys in the Customer table and how can I implement this in MySQL? Updated I am developing a web based accounting system for a final project. Account Category Account Type --------------Balance Assets