primary-key

primary key duplicate record bypass to next insert

瘦欲@ 提交于 2019-12-21 17:42:46
问题 weird question. i am inserting 10,000 records or so in a table and the primary key is not an Identity field. so when inserting all 10,000 if some are duplicate, is there a way to skip to next record in sql server insert and make sure the non-duplicates go in? i really dont care bout the duplicates not getting inserted. 回答1: Use the "Ignore duplicate key" option. The simplest way to do this is to delete the Primary Key in SQL Server Management Studio. Then create a new Index, of type "Index",

Room composite Primary Key link to Foreign Key

落花浮王杯 提交于 2019-12-21 12:18:27
问题 I am implementing an android application with Room database and have a small question about relationships in this DB. I have two tables: @Entity(tableName = "foods", primaryKeys = {"id", "language_id"}, indices = {@Index(value = {"id", "language_id"}, unique = true)}, inheritSuperIndices = true) public class Food { @NonNull @ColumnInfo(name = "id") private String mId; @NonNull @ColumnInfo(name = "language_id") private String mLanguageId; } @Entity(tableName = "ingredients", primaryKeys = {"id

Insert multiple rows with incremental primary key sql

孤者浪人 提交于 2019-12-21 05:24:16
问题 INSERT INTO TABLE1 (COLUMN1, PRIMARY_KEY) SELECT COLUMN1, (SELECT COALESCE(MAX(PRIMARY_KEY), 0) FROM TABLE1) + 1 FROM TABLE2 error: Violation of Primary Key constraint. Cannot insert duplicate key in object. How do I make the primary key increment after the first row? I would like to be able to add a list of items to this table at the same time instead of inserting them RBAR. Thanks for the help 回答1: INSERT INTO TABLE1 (COLUMN1, PRIMARY_KEY) SELECT COLUMN1, (SELECT COALESCE(MAX(PRIMARY_KEY),0

multicolumn primary keys in rails

柔情痞子 提交于 2019-12-21 05:09:12
问题 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,

How to define a VB.NET DataTable Column as primary key after creation

谁说我不能喝 提交于 2019-12-21 01:21:30
问题 I am importing Tables from a Oracle DataBase, using a VB.NET dataAdapter. I use the "fill" command to add the imported data to a DataSet. How is it possible to define a specific column of a DataTable as PrimaryKey, after the DataTable is already filled with data? 回答1: You can set the primary key of a table by: Dim table As New DataTable() table.Columns.Add(New DataColumn("MyColumn")) Dim primaryKey(1) As DataColumn primaryKey(1) = table.Columns("MyColumn") table.PrimaryKey = primaryKey To be

Creating django objects with a random primary key

半城伤御伤魂 提交于 2019-12-20 20:15:15
问题 I'm working with an API that wants me to generate opaque "reference IDs" for transactions with their API, in other words, unique references that users can't guess or infer in any way. (is 'infer' proper english?) This is what I've hacked together currently: randomRef = randint(0, 99999999999999) while Transaction.objects.filter(transactionRef = randomRef).count(): randomRef = randint(0, 99999999999999) Transaction.objects.create(user=user, transactionRef=randomRef, price=999) unfortunately my

Primary key versus key

你说的曾经没有我的故事 提交于 2019-12-20 18:27:10
问题 When creating a mysql dump containing the structure of my database, one of the tables shows the following: CREATE TABLE `completedTransactions` ( `paymentId` int(10) unsigned NOT NULL, `timestamp` int(15) unsigned NOT NULL, `actionTaken` varchar(25) NOT NULL, `response` varchar(255) NOT NULL, `responseCode` int(5) NOT NULL, PRIMARY KEY (`paymentId`,`timestamp`), KEY `paymentId` (`paymentId`), The primary key is what I was expecting, but I'm unsure what the last line is about? KEY `paymentId`

MySQL - Using foreign key as primary key too

蹲街弑〆低调 提交于 2019-12-20 11:09:08
问题 I have table 1 with a primary key user_id and table 2 where user_id is a foreign key. Only 1 record per user_id can exist in table 2, and no record can exist without it. QUESTION: Can user_id in table 2 be both foreign and primary key at the same time, and if yes, is it a good idea, what are pros/cons? 回答1: Yes, you can do this (and you should, from a database design point of view). However, consider what it means if user_id is the primary key on table 2. You are in effect saying that each

Change primary key in PostgreSQL table

余生长醉 提交于 2019-12-20 09:12:38
问题 I have users table in my PostgreSQL 9.3.6 database with two columns: id and another_id . The id is a primary key, the another_id is just another integer column with unique constraint. There are other tables that reference users by primary key. Here's the users table description: Table "public.users" Column | Type | Modifiers | Storage | Stats target | Description ----------------------+--------------------------------+----------------------------------------+---------+--------------+---------

Primary & Foreign Keys in pgAdmin

醉酒当歌 提交于 2019-12-20 08:42:49
问题 I was wondering can some give me an explanation on how to assign primary and foreign keys in pgAdmin? I can't find any information online. For example...I've got a Student table with all their details (address, d.o.b. and etc.). I'm going to add a student_number to the table and make it a primary key. I just want to know how do I do that using pgAdmin? And if you may be kind to explain give me further information on using Primary Keys in postgreSQL (and pgAdmin). The same case with the