primary-key

SQL Server “pseudo/synthetic” composite Id(key)

不羁的心 提交于 2020-01-09 03:53:12
问题 Sorry but I don't know how to call in the Title what I need. I want to create an unique key where each two digits of the number identify other table PK. Lets say I have below Pks in this 3 tables: Id Company Id Area Id Role 1 Abc 1 HR 1 Assistant 2 Xyz 2 Financial 2 Manager 3 Qwe 3 Sales 3 VP Now I need to insert values in other table, I know that I may do in 3 columns and create a Composite Key to reach integrity and uniqueness as below: Id_Company Id_Area Id_Role ...Other_Columns..... 1 2 1

Number or char for primary key column

女生的网名这么多〃 提交于 2020-01-07 02:19:12
问题 I'm building a database of a very important state institution. So far, for Primary Key columns I've sometimes used numbers, particularly int32 or int64, and sometimes I've used char but still I stored only numeric characters. Since this a very crucial task I have to make it both performance and comfort-wise efficient. Now I want to know,if it makes any difference to use number or char for a PK column considering the values in the char column will still be numeric characters. P.S.You might

How to have unique primary key in two tables?

﹥>﹥吖頭↗ 提交于 2020-01-06 07:46:12
问题 I have two tables in my system EMPLOYEE and EMPLOYEE_FORECAST . Both have the same columns, entire structure is same. I have another archive table with same structure called EMPLOYEE_ARCHIVE table. I need to put data from both tables to this archive table. Since records in EMPLOYEE and EMPLOYEE_FORECAST may have same primary key e.g. a record in EMPLOYEE will have a pk of say 100 and another record in EMPLOYEE_FORECAST may also have pk of 100 and this will definitely happen so when they are

Concurrency Problem With MySql Last_Insert_Id()… (C#)

ε祈祈猫儿з 提交于 2020-01-06 06:03:27
问题 I'm not really sure why the following console application doesn't produce the expected behavior for last_insert_id(). I've read that last_insert_id() returns the last auto_incremented value for a particular connection, but in this code, the same result is returned for both connections. Can someone explain where I've gone wrong? static void Main(string[] args) { string ConnectionString = "server=XXXX;database=XXXX;username=XXXX;password=XXXX;pooling=true;max pool size=100;min pool size=0";

Why are numbers being skipped in my auto-increment primary key?

岁酱吖の 提交于 2020-01-06 04:57:06
问题 Using MySQL 5.1.37 This isn't really a critical issue, one of our biz-dev people just asked about it and I didn't have a good answer. In our users table we have an auto-increment primary key. From time to time, it skips numbers and seems to be doing so at an increasing rate. My original thought was that when two concurrent signups occurred and one was invalid, that if the second signup was in progress while the first was failing, we would see skipped values since the second signup would use

É vs. E in MySQL database

与世无争的帅哥 提交于 2020-01-06 02:57:26
问题 MySQL thinks É and E are the same and thus throw an exception saying Duplicate entry 'CLEME' for key 'PRIMARY' MySQL is 5.1.30 and the table uses utf8-unicode-ci and the field is defined as follows: search_key varchar(120) CHARACTER SET latin1 NOT NULL, Is there a way to let this field know they are not the same? Thanks! 回答1: Change the character set of the field to UTF-8 as well. Also, set the connection character set to UTF-8 when you do the insert. 来源: https://stackoverflow.com/questions

Foreign key in composite primary key

China☆狼群 提交于 2020-01-05 11:47:10
问题 I have the following 3 tables: tblA ID - PK name tblB ID - PK tblAID - FK references tblA.ID pkID2 tblC ID - PK tblAID * fkID2 * ... I want to make this tuple a FK of (tblB.tblAID, tblB.pkID2) If I do this: alter table tblC with check add constraint FK_tblC_tblB foreign key (tblAID, fkID2) references tblB (tblAID, pkID2) I get an error message: There are no primary or candidate keys in the referenced table 'tblB' that match the referencing column list in the foreign key 'FK_tblC_tblB' I.e.: I

MVC EF Reverse Engineer Code First primary key column/member missing from views in auto-generated code

寵の児 提交于 2020-01-05 08:59:55
问题 I am using an EF Reverse Engineer Code First project. Specifically, I used the Entity Model, code first from database method that allows one to select only a subset of the database tables for a particular MVC project. The primary key column/member for one of my table models is present in the table model, but when I auto-generated the views from the controller the primary key column/member is missing, except from the Create View. Is this standard behavior for the new version 6 -- Visual Studio

how to update primary key value in sql?

萝らか妹 提交于 2020-01-05 08:38:33
问题 I have a country table which have a column Countryid I accidently deleted the CountryId Which Had value=1 and now in state table there is a value of column countryId=1 which is used to fetch the records (states) according to country id. I had inserted the country again but it has different id so how can I update the value again in country table of CountryId which primary key from 2 to 回答1: The direct answer to your question is to use set identity_insert off . The best place to start is with

Using datetime float representation as primary key

与世无争的帅哥 提交于 2020-01-05 04:21:12
问题 From my experience I have learn that using an surrogate INT data type column as primary key esp. an IDENTITY key column offers better performance than using GUID or char/varchar data type column as primary key. I try to use IDENTITY key as primary key wherever possible. But recently I came across a schema where the tables were horizontally partitioned and were managed via a Partitioned view. So the tables could not have an IDENTITY column since that would make the Partitioned View non