primary-key

composite (alphanumeric) primary key and auto increment

╄→尐↘猪︶ㄣ 提交于 2019-12-01 14:26:59
Is it possible to make an auto-increment function in MySQL that combines alpha elements and numeric? I have an existing system with keys like QAb99, QAb101, QAd9003, etc. The max numeric portion ranges from 1 to 9999, while the letters begin with QA and range from QAa to QAd, etc. and will eventually pass QAd9999 to QAe1, etc. Is it better to manage generating new keys in SQL or outside of SQL (i.e. php script)? thanks. I asked this a while ago. Mysql doesn't do this unfortunately. I'd love it to, but it just doesn't. In php you could do it. Example: public function random_id_gen($length) { /

Can I keep old keys linked to new keys when making a copy in SQL?

大城市里の小女人 提交于 2019-12-01 12:38:19
I am trying to copy a record in a table and change a few values with a stored procedure in SQL Server 2005. This is simple, but I also need to copy relationships in other tables with the new primary keys. As this proc is being used to batch copy records, I've found it difficult to store some relationship between old keys and new keys. Right now, I am grabbing new keys from the batch insert using OUTPUT INTO. ex: INSERT INTO table (column1, column2,...) OUTPUT INSERTED.PrimaryKey INTO @TableVariable SELECT column1, column2,... Is there a way like this to easily get the old keys inserted at the

JPA: @JoinTable - Both columns are Primary Keys.. How do I stop that?

痴心易碎 提交于 2019-12-01 12:11:03
This is my annotation I use to generate my Join Table. @OneToMany(cascade = CascadeType.ALL) @JoinTable(name = "service_operations", joinColumns = { @JoinColumn(name = "serviceId") }, inverseJoinColumns = { @JoinColumn(name = "operationId") }) public Set<Operation> getOperations() { return operations; } Considering this is a OneToMany association, my natural assumption is that this table would generate a [ Primary Key | Foreign Key ] table, however everytime I drop and re create the database it is not the case: mysql> describe workflow_services; +-------------+------------+------+-----+-------

Database Design: Composite key vs one column primary key

我是研究僧i 提交于 2019-12-01 11:21:05
A web application I am working on has encountered an unexpected 'bug' - The database of the app has two tables (among many others) called 'States' and 'Cities'. ' States ' table fields: ------------------------------------------- idStates | State | Lat | Long ------------------------------------------- ' idStates ' is an auto-incrementing primary key. ' Cities ' table fields: ---------------------------------------------------------- idAreaCode | idStates | City | Lat | Long ---------------------------------------------------------- ' idAreaCode ' is a primary key consisting of country code +

Can I keep old keys linked to new keys when making a copy in SQL?

梦想的初衷 提交于 2019-12-01 11:10:24
问题 I am trying to copy a record in a table and change a few values with a stored procedure in SQL Server 2005. This is simple, but I also need to copy relationships in other tables with the new primary keys. As this proc is being used to batch copy records, I've found it difficult to store some relationship between old keys and new keys. Right now, I am grabbing new keys from the batch insert using OUTPUT INTO. ex: INSERT INTO table (column1, column2,...) OUTPUT INSERTED.PrimaryKey INTO

Give composite primary key in Rails

独自空忆成欢 提交于 2019-12-01 10:52:55
How can i give composite primary key in Rails without any gem? My first table in migration file: class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :userid t.string :name t.string :address t.timestamps end end def self.down drop_table :users end end My second table in migration file: class CreateProjects < ActiveRecord::Migration def self.up create_table :projects do |t| t.string :title t.string :description t.timestamps end end def self.down drop_table :projects end end In my schema file: ActiveRecord::Schema.define(:version => 20110222044146) do

JPA: @JoinTable - Both columns are Primary Keys.. How do I stop that?

≯℡__Kan透↙ 提交于 2019-12-01 09:53:32
问题 This is my annotation I use to generate my Join Table. @OneToMany(cascade = CascadeType.ALL) @JoinTable(name = "service_operations", joinColumns = { @JoinColumn(name = "serviceId") }, inverseJoinColumns = { @JoinColumn(name = "operationId") }) public Set<Operation> getOperations() { return operations; } Considering this is a OneToMany association, my natural assumption is that this table would generate a [ Primary Key | Foreign Key ] table, however everytime I drop and re create the database

Database Design: Composite key vs one column primary key

Deadly 提交于 2019-12-01 09:38:56
问题 A web application I am working on has encountered an unexpected 'bug' - The database of the app has two tables (among many others) called 'States' and 'Cities'. ' States ' table fields: ------------------------------------------- idStates | State | Lat | Long ------------------------------------------- ' idStates ' is an auto-incrementing primary key. ' Cities ' table fields: ---------------------------------------------------------- idAreaCode | idStates | City | Lat | Long -----------------

How to get generated keys by executeBatch without ArrayIndexOutOfBoundsException?

回眸只為那壹抹淺笑 提交于 2019-12-01 09:22:56
The following method I want to INSERT several records simultaneously. public void insert() { try { this.connection.setAutoCommit(false); PreparedStatement ps = this.connection.prepareStatement( "INSERT INTO COMPANY (NAME,Address) Values (?,?)", new String[]{"ID"}); ps.setString(1, "X01"); ps.setString(2, "Address1"); ps.addBatch(); ps.setString(1, "Y01"); ps.setString(2, "Address2"); ps.addBatch(); //EXCEPTION OCCURS HERE int[] numUpdates = ps.executeBatch(); for (int i = 0; i < numUpdates.length; i++) { System.out.println("Execution " + i + "successful: " + numUpdates[i] + " rows inserted");

Give composite primary key in Rails

倖福魔咒の 提交于 2019-12-01 09:09:24
问题 How can i give composite primary key in Rails without any gem? My first table in migration file: class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :userid t.string :name t.string :address t.timestamps end end def self.down drop_table :users end end My second table in migration file: class CreateProjects < ActiveRecord::Migration def self.up create_table :projects do |t| t.string :title t.string :description t.timestamps end end def self.down drop