我有一张桌子:
table votes (
id,
user,
email,
address,
primary key(id),
);
Run Code Online (Sandbox Code Playgroud)
现在我想使列用户,电子邮件,地址唯一(一起).
我如何在MySql中执行此操作?
在这段代码中,如何为复合键生成Java类(如何在hibernate中复合键):
create table Time (
levelStation int(15) not null,
src varchar(100) not null,
dst varchar(100) not null,
distance int(15) not null,
price int(15) not null,
confPathID int(15) not null,
constraint ConfPath_fk foreign key(confPathID) references ConfPath(confPathID),
primary key (levelStation, confPathID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Run Code Online (Sandbox Code Playgroud) 这是我正在使用的激烈设置的粗略过度简化.table_1并且table_2两者都有自动增加代理主键作为ID.info是一个包含有关table_1和的信息的表table_2.
table_1 (id, field)
table_2 (id, field, field)
info ( ???, field)
Run Code Online (Sandbox Code Playgroud)
我试图决定,如果我应该做的主键info的ID从复合材料table_1和table_2.如果我这样做,哪一个最有意义呢?
(在这个例子中,我将ID 11209与ID 437相结合)
INT(9)11209437 (我可以想象为什么这很糟糕)
VARCHAR (10) 11209-437
DECIMAL (10,4)11209.437
或者是其他东西?
将它用作MYSQL MYISAM数据库的主键可以吗?
mysql myisam primary-key composite-key composite-primary-key
我试图找出如何使用EF代码First 4.1 RC获得复合键.
目前,我正在使用[Key] Data Annotation,但我无法指定多个键.
如何指定复合键?
这是我的例子:
public class ActivityType
{
[Key]
public int ActivityID { get; set; }
[Required(ErrorMessage = "A ActivityName is required")]
[StringLength(50, ErrorMessage = "Activity Name must not exceed 50 characters")]
public string ActivityName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我需要"ActivityName"也是一个关键.当然,我可以围绕这个编码,但那不是很好的数据库设计.
我无法理解创建复合键时的语法错误.这可能是一个逻辑错误,因为我已经测试了许多品种.
如何在Postgres中创建复合键?
CREATE TABLE tags
(
(question_id, tag_id) NOT NULL,
question_id INTEGER NOT NULL,
tag_id SERIAL NOT NULL,
tag1 VARCHAR(20),
tag2 VARCHAR(20),
tag3 VARCHAR(20),
PRIMARY KEY(question_id, tag_id),
CONSTRAINT no_duplicate_tag UNIQUE (question_id, tag_id)
);
ERROR: syntax error at or near "("
LINE 3: (question_id, tag_id) NOT NULL,
^
Run Code Online (Sandbox Code Playgroud) 我在MVC 3应用程序中使用Entity framework 4.1.我有一个实体,我有主键由两列(复合键)组成.并且这在另一个实体中用作外键.如何建立关系?在普通的scnerios我们使用:
public class Category
{
public string CategoryId { get; set; }
public string Name { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public string CategoryId { get; set; }
public virtual Category Category { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是如果类别有两列键怎么办?
c# entity-framework foreign-keys composite-key ef-code-first
不久,我想在我的表上创建复合键,保留主键,以提高sql server搜索性能.每当我搜索没有主键的实体(即一串GUID)时,性能问题就会发生在200k数据表上.假设我有3个班级
public class Device{
public int ID { get; set; }
public string UDID { get; set; }
public string ApplicationKey { get; set; }
public string PlatformKey { get; set; }
public ICollection<NotificationMessageDevice> DeviceMessages { get; set; }
}
public class NotificationMessageDevice {
[Column(Order = 0), Key, ForeignKey("NotificationMessage")]
public int NotificationMessage_ID { get; set; }
[Column(Order = 1), Key, ForeignKey("Device")]
public int Device_ID { get; set; }
public virtual Device Device { get; set; }
public virtual NotificationMessage …Run Code Online (Sandbox Code Playgroud) 如何在phpmyadmin上创建复合主键.这样学生ID就是年份和卷号的组合.sid = 112132,2011年11月和2132年是滚动数?任何人都帮忙..
我首先要掌握EF4代码,并且喜欢它到目前为止.但是我无法将实体映射到具有复合主键的表.
我试过的配置看起来像这样:
public SubscriptionUserConfiguration()
{
Property(u => u.SubscriptionID).IsIdentity();
Property(u => u.UserName).IsIdentity();
}
Run Code Online (Sandbox Code Playgroud)
抛出此异常:无法推断实体类型"SubscriptionUser"的密钥.
我错过了什么?
我们有一个表,其中包含一个由三个字段组成的复合主键(它在MySQL 5.1中).此表上每秒有近200个插入和200个选择,表的大小约为100万行,并且正在增加.
我的问题是:"复合主键"是否会降低此表上的插入和选择的性能?
我应该使用简单的自动增加INT ID字段而不是复合主键吗?(我认为答案与MySQL处理多列索引的方式有很大关系)
composite-key ×10
mysql ×4
c# ×2
orm ×2
primary-key ×2
foreign-keys ×1
hibernate ×1
hql ×1
java ×1
myisam ×1
performance ×1
phpmyadmin ×1
postgresql ×1
sql ×1