primary-key

SQL Table Foreign Key that is part of a Composite Primary Key

倖福魔咒の 提交于 2019-12-30 09:22:08
问题 Is it possible to have a table's foreign key be part of another table's composite primary key? For example, if I have two tables, one contains information on all active projects of different users and another containing information on what equipment is being used by the projects: Project Table: Composite Primary Keys: UserId, ProjectId (neither are unique by themselves) Equipment Table: Composite Primary Keys: UserId, ProjectId, EquipmentId (neither are unique by themselves) Now is it

Insert Where Not Exists-Without Primary Key

杀马特。学长 韩版系。学妹 提交于 2019-12-30 03:20:13
问题 I have 3 tables: dentists, groups, and groupdentlink. Many dentists link to many groups through the groupdentlink table. So I'm trying to make a query where it will insert rows into groupdentlink (linking all dentists in the state with all the groups in the state) but only if those rows don't already exist. In a nutshell I want to add new rows without overwriting existing ones or duplicating them. So the intent of the query is something like: INSERT INTO groupdentlink (f_dent_id, f_group_id,

How to get generated keys from JDBC batch insert in Oracle?

做~自己de王妃 提交于 2019-12-29 04:45:08
问题 I am inserting many records using JDBC batch inserts. Is there any way to get the generated key for each record? Can I use ps.getGeneratedKeys() with batch inserts? I am using oracle.jdbc.OracleDriver final String insert = "Insert into Student(RollNumber, Name, Age) values(StudentSEQ.nextval, ? , ?)"; final int BATCH_SIZE = 998; int count = 0; Connection con = null; PreparedStatement ps = null; try { con = getConnection(); ps = con.prepareStatement(insert); for (Student s : students) { ps

Attaching an entity of type failed because another entity of the same type already has the same primary key value.

喜欢而已 提交于 2019-12-28 18:14:42
问题 Let me quickly describe my problem. I have 5 databases for 5 customers and each has the same table called SubnetSettings . I already created a dropdownlist to select a customer and will shows up the SubnetSetting table which belong to selected customer and allow me to create, edit and delete. I can create, delete without problem but when I want to edit the data it brings the error: Server Error in '/TMS' Application. Attaching an entity of type 'CFS.Domain.Entities.SubnetSettings' failed

Easy mysql question regarding primary keys and an insert

為{幸葍}努か 提交于 2019-12-28 06:04:16
问题 In mysql, how do I get the primary key used for an insert operation, when it is autoincrementing. Basically, i want the new autoincremented value to be returned when the statement completes. Thanks! 回答1: Your clarification comment says that you're interested in making sure that LAST_INSERT_ID() doesn't give the wrong result if another concurrent INSERT happens. Rest assured that it is safe to use LAST_INSERT_ID() regardless of other concurrent activity. LAST_INSERT_ID() returns only the most

Use item specific prefixes and autonumber for primary keys?

纵饮孤独 提交于 2019-12-28 05:52:30
问题 We had a meeting this morning about how would should store our ID for some assets that we have in our database that we are making, the descusion generated a bit of heat so I decided to consult the experts of SO. The table structure that I belive that we should have(short version) is like the following: Example 1) AssetId - int(32) - Primary Key Type - string so some example data is like this: ==AssetId======Type=== 12345 "Manhole" 155415 "Pit" etc. Another member of the team suggested

Dynamics AX 2012 R3 - Record Creation through AIF web service

百般思念 提交于 2019-12-25 08:57:28
问题 I am having issues using an AIF web service to create a unique primary key in our contract module in Dynamics AX. Our contract PK's are in a format of 'CON-######', and the contractId is tied to a number sequence in AX. When I call the 'Create' service operation, I am passing a 0 for 'ContractId' and AX is not replacing that 0 with an actual contract Id from the number sequence. The AX service endpoint is configured as an enhanced port. Is there a setting that needs to be enabled on the AX

Should I use Natural Identity Columns without GUID?

有些话、适合烂在心里 提交于 2019-12-25 04:57:48
问题 Is it ok to define tables primary key with 2 foreign key column that in combination must be unique? And thus not add a new id column (Guid or int)? Is there a negative to this? 回答1: Yes, it's completely OK. Why not? The downside of composite primary keys is that it can be long and it might be harder to identify a single row uniquely from the application perspective. However, for a couple integer columns (specially in junction tables), it's a good practice. 回答2: Natural versus Artificial

MySQL foreign key causing table to drop

落爺英雄遲暮 提交于 2019-12-25 04:56:07
问题 had an issue before with this code which was resolved and caused the table to work but now i am receiving error 1005 and the table cannot be created due to the fk here is the code for the first table SET FOREIGN_KEY_CHECKS = 0; DROP TABLE IF EXISTS Customer; CREATE TABLE Customer ( CustomerNumber int NOT NULL, CustomerName varchar(255), CustomerAddress varchar(255), CustomerPhoneNumber varchar(255), JoinDate varchar(255), PetName varchar(255), PayScheme varchar(255), PremiumPayDate varchar

normalization of database

陌路散爱 提交于 2019-12-25 02:24:48
问题 I would like to ask about a question relating to normalization. I have 2 PKs, VIN and Reg_no. VIN is the Vehicle ID Number and Registration number is the car plate number. I have an attribute called current odometer. Does it have a partial dependency or a full dependency on the 2 PKs? 回答1: I have 2 PKs, VIN and Reg_no. VIN is the Vehicle ID Number and Registration number is the car plate number. You have two candidate keys. VIN is unique; the plate number is also probably unique. (But it