是否可以在SQL Server中重命名约束?我不想删除并创建一个新约束,因为这个约束会影响其他已存在的约束,我将不得不重新创建/更改它们.
我需要删除StudentSQL Server数据库中表的主键.
我已经在表格中编辑了,我得到的脚本是
ALTER TABLE dbo.Student
DROP CONSTRAINT PK__Student__9CC368536561EF8B
Run Code Online (Sandbox Code Playgroud)
但是当我在SQL Server查询浏览器中运行此脚本以删除主键时
它显示了该消息
Msg 3728,Level 16,State 1,Line
1'PK__Student__9CC368536561EF8B'不是约束.
Msg 3727,Level 16,State 0,Line 1
令我担心的是,我认为PK__Student__9CC368536561EF8B这将随机生成,请帮助我使用脚本删除主键约束.
提前致谢
我正在尝试将我的代码第一个ID列从"int"更改为"Guid",并且在尝试运行迁移时,我收到消息:
Identity column 'CustomFieldId' must be of data type int, bigint, smallint, tinyint, or decimal or numeric with a scale of 0, and constrained to be nonnullable.
Run Code Online (Sandbox Code Playgroud)
我正在定义这样的列:
public partial class CustomField : BaseEntity
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid CustomFieldId { get; set; }
Run Code Online (Sandbox Code Playgroud)
在CustomFieldMapping.cs中映射它,如下所示:
public CustomFieldMapping()
{
//Primary key
HasKey(t => t.CustomFieldId);
//Constraints
Property(t => t.CustomFieldId).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Run Code Online (Sandbox Code Playgroud)
并且生成的迁移正在尝试执行此操作:
public override void Up()
{
DropForeignKey("dbo.CustomField", "CustomFormId", "dbo.CustomForm");
DropForeignKey("dbo.CustomData", "CustomFieldId", "dbo.CustomField");
DropForeignKey("dbo.CustomForm", "ParentFormId", "dbo.CustomForm");
DropIndex("dbo.CustomField", new[] { "CustomFormId" });
DropIndex("dbo.CustomForm", new[] { …Run Code Online (Sandbox Code Playgroud)