primary-key

Foreign key as Primary key

淺唱寂寞╮ 提交于 2019-12-10 16:21:20
问题 I designed tables like this: table1: students --------------------- PK id name number ... --------------------- table2: students_score --------------------- PK FK student_id math_score english_score ... --------------------- Question 1 If some students doesn't have scores at all, is it good table design? Question 2 If it's good design, then how can I make FK as PK in MySQL? I can't find out how. Everytime I try to make a relation like above SQLYog says this error: Can't create table 'students

In SQL server how do I order table rows by insertion order if primary key is GUID?

这一生的挚爱 提交于 2019-12-10 15:35:30
问题 I've started using GUIDs over auto-increment integers for my primary keys. However, during development I'm used to querying (from SQL management studio or visual studio) database in order to see what records my application just inserted, and I'm pissed off by the fact that I cannot order by primary key desc in order to see the most recent records. Is there a way to accomplish tihs? 回答1: You can't order a GUID column based on insertion order. You'll need to rely on another column. My

set_primary_key error in Rails

你离开我真会死。 提交于 2019-12-10 14:47:51
问题 I'm creating a table called Index . Here's the migration: class CreateIndices < ActiveRecord::Migration def change create_table :indices, {:id => false} do |t| t.string :name t.float :returns, array: true, default: [] t.float :navs, array: true, default: [] t.float :sharpe t.timestamps end execute "ALTER TABLE indices ADD PRIMARY KEY (name);" end end That all works fine. I saw in another Stack Overflow question that I have to include the set_primary_key command in my model to get it to work,

Can a primary key default be NULL? Why is it described as such?

可紊 提交于 2019-12-10 14:34:20
问题 I have a table that when I describe it is: mysql> DESC my_table; +------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+-------------+------+-----+---------+----------------+ | contact_id | int(11) | NO | PRI | NULL | auto_increment | | location | varchar(20) | YES | | NULL | | | city | varchar(20) | YES | | NULL | | | state | varchar(2) | YES | | NULL | | +------------+-------------+------+-----+---------+-----------

Enforcement of unique/primary key - drop index

夙愿已清 提交于 2019-12-10 14:05:01
问题 I am trying to drop an index : DROP INDEX PK_CHARGES but I get this error cannot drop index used for enforcement of unique/primary key Why I am getting this error? I will provide further information if you need any. How to solve it? Edit I have no primary key in the table, but I found this weird index that I don't remember I had added: index name = SYS_C0040476 which have the same columns 回答1: You can query the ALL_CONSTRAINTS performance view to see which constraint the index is used by, and

Edmx need Primary_Key?

≯℡__Kan透↙ 提交于 2019-12-10 13:24:04
问题 Its a problem While Creating Edmx in .net that on creating Edmx of DataBase only those Tables and views are added who had a primary key. This problem resolved easily but just making a column primary key in Table or View but i didn't got the actual reason why it is necessary?? Can anyone please explain the reason behind it? 回答1: Entity Framework needs a primary key to properly identify a piece of data as unique in a particular set of data. It comes down to how it looks up entities internally

Laravel 4 using UUID as primary key

倾然丶 夕夏残阳落幕 提交于 2019-12-10 13:19:41
问题 I am setting up my first Laravel 4 app and the specs call for the id fields to be varchar(36) and be a UUID. Using Eloquent, my migrations for a sample table looks like this: Schema::create('users', function($table) { $table->string('id', 36)->primary; $table->string('first_name', 50); $table->string('last_name', 50); $table->string('email')->unique(); $table->string('password', 60); $table->timestamps(); $table->softDeletes(); }); When the users table gets created, the id field is not

Merge multiple Excel workbooks based on key column

旧城冷巷雨未停 提交于 2019-12-10 12:48:10
问题 I get seven workbooks (xlsx files) from different clients, each with one sheet. Each sheet has at least one common ID column (UNIQ, PK). One of the workbook contains list of all possible ids. Others may not have record for all ids, but each row has id value defined. I need to make a final workbook, with first column ID and then union of all remaining columns from each file. Then I need to send the final.xlsx via email, so its independent of the source files (I'm not sure if its possible to

Sql Server: uniqueidentifier plus integer compound PK … what type of index to use?

十年热恋 提交于 2019-12-10 10:39:36
问题 I have a junction table in my SQL Server 2005 database that consist of two columns: object_id (uniqueidentifier) property_id (integer) These values together make a compound primary key. What's the best way to create this PK index for SELECT performance? If the columns were two integers, I would just use a compound clustered index (the default). However, I've heard bad things about clustered indexes when uniqueidentifiers are involved. Anyone have experience with this situation? 回答1: Yes, GUID

How reorder primary key?

☆樱花仙子☆ 提交于 2019-12-10 09:56:43
问题 I have deleted one row(row 20) in my "table category" ,please let me know that how can i reorder the catid (primary key)? at this time it is 21 after 19. Thanks 回答1: You cannot. The closest you can get is truncate table , which will drop the table and recreate it, which means you lose all data in it, and the ID counter is reset to 0. Other than that, ID will always increment by one from the last inserted record, no matter if that record still exists or not. You can write a query to fix all