Adding Primary Keys and Foreign Keys to a Table

Grok免费接入Google Workspace:AI文档协作实战指南 对话式AI模型作为自然语言处理技术的重要分支,通过深度学习算法实现人机智能交互。其技术原理基于Transformer架构,能够理解上下文语义并生成连贯回复。在工程实践中,AI模型与办公套件的集成显著提升了文档协作效率,通过API网关实现功能扩展。Google Workspace作为云端办公平台,与Grok AI的整合为文档写作、数据分析和演示生成提供了智能化解决方案。这种技术组合特别适合需要实时AI辅助的团队协作场景,用户可以在Google Docs中调用Grok进行内容续写,在Sheets中用自然语言处理 阅读详情

<script language="C#" runat="server">

 void Page_Load(Object sender, EventArgs e)
 {

  // get connection string from ../global/connect-strings.ascx user control
  string strConnect = ctlConnectStrings.OLEDBConnectionString;
  outConnect.InnerText = strConnect; // and display it

  // specify the SELECT statement to extract the BookList data
  string strSelectBooks = "SELECT * FROM BookList WHERE ISBN LIKE '18610033%'";
  outSelectBooks.InnerText = strSelectBooks;   // and display it

  // specify the SELECT statement to extract the BookAuthor data
  string strSelectAuthors = "SELECT * FROM BookAuthors WHERE ISBN LIKE '18610033%'";
  outSelectAuthors.InnerText = strSelectAuthors;   // and display it

  // declare a variable to hold a DataSet object
  DataSet objDataSet = new DataSet();

  try
   {
   // create a new Connection object using the connection string
   OleDbConnection objConnect = new OleDbConnection(strConnect);

   // create a new Command object
   OleDbCommand objCommand = new OleDbCommand();

   // set the properties
   objCommand.Connection = objConnect;
   objCommand.CommandType = CommandType.Text;
   objCommand.CommandText = strSelectBooks;

   // create a new DataAdapter object
   OleDbDataAdapter objDataAdapter = new OleDbDataAdapter();
   // and assign the Command object to it
   objDataAdapter.SelectCommand = objCommand;

   // get the data from the "BookList" table in the database and
   // put it into a table named "Books" in the DataSet object
   objDataAdapter.Fill(objDataSet, "Books");

   // change the SELECT statement in the Command object
   objCommand.CommandText = strSelectAuthors;
   // then get data from "BookAuthors" table into the DataSet
   objDataAdapter.Fill(objDataSet, "Authors");
  }
  catch (Exception objError)
  {
   // display error details
   outError.InnerHtml = "<b>* Error while accesing data</b>.<br />"
     + objError.Message + "<br />" + objError.Source;
   return;  //  and stop execution

  }

  // now that the DataSet is filled, we can modify the tables it contains
  // declare variables to refer to the DataTable and a DataColumn objects
               
  DataTable objParentTable = objDataSet.Tables["Books"];//父表
  DataTable objChildTable = objDataSet.Tables["Authors"];//子表
  DataColumn objParentColumn = objParentTable.Columns["ISBN"];//父表的ISBN列
  DataColumn objChildColumn = objChildTable.Columns["ISBN"];//子表ISBN列

  // create a new UniqueConstraint object and add to Constraints collection
                //创建主键约束
  UniqueConstraint objUnique = new UniqueConstraint("Unique_ISBN", objParentColumn);//Unique_ISBN是约束名,objParentColumn是主键约束列
  objParentTable.Constraints.Add(objUnique);//添加约束
      
  // prevent the column from accepting Null values
  objParentColumn.AllowDBNull = false;

  // create an array of columns containing this column only
               
  DataColumn[] objColumnArray = new DataColumn[1];
  objColumnArray[0] = objParentColumn;

  // and set this array as the columns for the Primary Key of the table
               //指定主键(是一个DataColumn数组,保证只有唯一标号。此处只有ISBN一列)
  objParentTable.PrimaryKey = objColumnArray;

  // now we can process the child table named "Authors"
  // create an array of columns containing the ISBN and Lastname columns
                
  objColumnArray = new DataColumn[2];
  objColumnArray[0] = objChildColumn;    // the ISBN column
  objColumnArray[1] = objChildTable.Columns["Lastname"];

  // prevent either of these columns containing Null
  objColumnArray[0].AllowDBNull = false;
  objColumnArray[1].AllowDBNull = false;
  
  // set this column array as the primary key
             //指定主键(由ISBN和Lastname两列组成的数组)
  objChildTable.PrimaryKey = objColumnArray;

  // create a new ForeignKeyConstraint object
                //指定外键
  ForeignKeyConstraint objFKey = new ForeignKeyConstraint("FK_BookAuthors",  objParentColumn, objChildColumn);
  // set the "update" properties
  objFKey.DeleteRule = Rule.Cascade;//级联
  objFKey.UpdateRule = Rule.Cascade;

  // and add it to the Constraints collection
  objChildTable.Constraints.Add(objFKey);

  // --------------------------------------------------------------
  // now we're ready to display the contents of the DataSet object
  // bind the collection of Tables to the first DataGrid on the page
  dgrTables.DataSource = objDataSet.Tables;
  dgrTables.DataBind();

  // bind the collection of Constraints to the second DataGrid on the page
  dgrBookCons.DataSource = objDataSet.Tables["Books"].Constraints;
  dgrBookCons.DataBind();

  // bind the collection of Constraints to the third DataGrid on the page
  dgrAuthorCons.DataSource = objDataSet.Tables["Authors"].Constraints;
  dgrAuthorCons.DataBind();

  // create a DataView object to use with the tables in the DataSet
  DataView objDataView = new DataView();

  // get the default view of the Books table into the DataView object
  objDataView = objDataSet.Tables["Books"].DefaultView;
  // and bind it to the next DataGrid on the page
  dgrBooksData.DataSource = objDataView;
  dgrBooksData.DataBind();

  // then do the same for the Authors table
  objDataView = objDataSet.Tables["Authors"].DefaultView;
  dgrAuthorsData.DataSource = objDataView;
  dgrAuthorsData.DataBind();

}
</script>


 

ORA-02266: unique/primary keys in table referenced by enabled foreign keys SQL> truncate table alert_store; truncate table alert_store * ERROR at line 1: ORA-02266: unique/primary keys in table referenced by enabled foreign keys SQL> SET PAGESIZE 100 阅读详情

相关推荐

整合WGCNA、机器学习和孟德尔随机化

(G)通过蛋白质免疫印迹法(Western blot)测定的 UT-B(由 SLC14A1 编码)、ARHGEF38、NEFH、MSMB、KRT23 和 KRT15 在前列腺癌肿瘤组织和癌旁非癌组织中的蛋白质表达水平。本研究利用来自基因表达综合数据库(GEO)的数据集筛选差异表达基因(DEGs),并采用加权基因共表达网络分析(WGCNA),以识别在模块中与前列腺癌高度相关的驱动基因。(F)蓝绿色模块中的模块成员关系(MM)与前列腺癌(PCa)的基因显著性(GS)的散点图。(D)6 个基因之间的相关性分析。

多组・学・多组学 1141

关于primary key和foreign key的问题处理

今天碰到一个问题,在drop primary key的时候,提示ORA-02273的错误。 SQL> ALTER TABLE AR1_ACCOUNT DROP PRIMARY KEY; ...

congbao6525的博客 671

MIPI video mode 和 command mode 的区别

1、何为LCD RAM? LCD 是指字面意思是液晶显示屏(Liquid Crystal Display), 而RAM: 随机存取存储器(Random-Access Memory),两者完全是风马牛不相及的东西。 下图是一个标准的LCD的爆炸图(不含TP),请注意图中红色mark的地方:控制IC-- LCD的大脑。所谓的LCD RAM自然是指此大脑是否包含RAM. 题外话<不感兴趣的...

精诚所至 4691

sql外键_SQL外键

sql外键When a database table is designed an important factor is to make sure that the table is scalable enough and is normalized at the same time. In order to make sure that the tables are well linked a...

从零开始的教程世界 1万+

别再混淆了!一张图看懂SAP特殊采购类30/40/70/80的区别与选型指南

本文深度解析SAP特殊采购类30/40/70/80的核心逻辑与业务影响,通过对比框架和真实案例帮助用户掌握其适用边界。重点介绍委外加工(类型30)、工厂间转移(类型40/70)及计划与执行分离(类型80)的配置要点与常见问题,提供选型决策树和实施检查清单,助力企业优化供应链管理。

weixin_26938645的博客 458

Win10环境下VS2019离线部署OnnxRuntime的完整指南

本文提供了在Windows 10系统下,为Visual Studio 2019进行OnnxRuntime离线部署的完整教程。针对网络受限环境,详细讲解了如何获取正确的离线安装包、配置本地NuGet源,并逐步指导项目配置与测试,确保AI模型在C++环境中顺利运行。

weixin_29205061的博客 401

MySQL之主键(PRIMARY KEY)和外键(FOREIGN KEY)的作用与使用

在关系型数据库中,主键(PRIMARY KEY)和外键(FOREIGN KEY)是用于定义数据表之间关系的关键约束。它们在数据完整性、查询性能、以及表之间的联系上扮演着重要角色。理解这两者的作用和如何使用它们,是设计高效和规范数据库的基础。主键是用于唯一标识表中每一条记录的字段或字段组合。主键的值必须是唯一的,并且不能为NULL。主键确保了数据表中每一行记录的唯一性,它是表中的一种约束。唯一性:主键保证了表中的每一条记录是唯一的,不会有重复的数据行。非空:主键的字段不能为NULL。

2201_75863687的博客 6146

DOTween回调函数的隐藏技巧:优化你的Unity动画流程

本文深入探讨了DOTween回调函数在Unity动画开发中的高级应用技巧,帮助开发者优化动画流程。通过分析回调机制、链式应用模式和大规模动画系统管理,提升性能与可维护性,特别适合需要高效处理复杂动画场景的Unity开发者。

weixin_27945229的博客 319

关系型数据库中主键(primary key)和外键(foreign key)的概念。

        刚接触关系型数据库的同学,会听过主键和外键的概念。这是关系型数据库的基本概念,需要清楚理解。今天我就以简洁的语言总结一下这个概念。         主键。一句话概括:一张表中,可以用于唯一标识一条记录的字段组(或者说是属性组)。给你一个主键的值,你就可以找到一条确定的记录。如:         学生表:学号,姓名,性别,课程。这里学号就是主键。给你一个学号,就可以找到一条学生记...

blues_more的专栏 6万+

nrf52840的uart0与uart1双串口使用

nrf52840的uart0与uart1双串口使用 项目原使用nrf52832,后面由于项目需要用到双串口,改用nrf52840,官方的例程没看到使用uart1的,找遍全网都没找到uart1的使用资料,有些不负责任的网文居然说40也只有一个uart,吓得俺赶紧又查看了一次datesheet,O得K、木鸭梨 SDK代码uart驱动中,搜索到uart1的驱动部分,说明官方驱动有uart1支持的 自己动手,丰衣足食吧,下面以nRF5_SDK_17.0.0_9d13099版本,在examples\ble_per

chhen168的博客 5627

别再只看图了!代谢组学OPLS-DA分析,R2Y和Q2Y到底怎么看才不踩坑?

本文深入解析代谢组学OPLS-DA分析中的关键指标R2Y和Q2Y,揭示如何避免过拟合陷阱。通过详细解读模型解释能力(R2Y)和预测能力(Q2Y),结合置换检验方法,提供完整的模型评估流程与实战建议,帮助研究者获得可靠的分析结果。

weixin_42638178的博客 196

ORA-02449: unique/primary keys in table referenced by foreign keys

[root@dbogg ~]# su - oracle [oracle@dbogg ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Thu Jul 15 10:24:45 2021 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 1.

sqlora的专栏 909

Python爬虫实战:手把手教你园林植物分类全维度字典自动化采集实战!

我长期专注 Python 爬虫工程化实战,主理专栏 👉 《Python爬虫实战》:从采集策略到反爬对抗,从数据清洗到分布式调度,持续输出可复用的方法论与可落地案例。内容主打一个“能跑、能用、能扩展”,让数据价值真正做到——抓得到、洗得净、用得上。

喵手的博客 389

Oracle/PLSQL: Foreign Keys

​ A foreign key means that values in one table must also appear in another table. The referenced table is called the parent table while the table with the foreign key is called the child table. The foreign key in the child table will generally reference

yuanlnet的博客 176

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

mysql中foreign keys_Foreign Keys and MySQL_MySQL

Foreign Keys are often a mystery to new DBAs in the MySQL world. Hopefully this blog will clear some of this up.In this example, we will have a table for employee data and a table for the data on offi...

weixin_32427105的博客 241

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

mysql create keys_How to properly create composite primary keys - MYSQL

问题Here is a gross oversimplification of an intense setup I am working with. table_1 and table_2 both have auto-increment surrogate primary keys as the ID. info is a table that contains information abo...

weixin_42300175的博客 259

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

truncate table 错误 ORA-02266: unique/primary keys in table referenced by enabled foreign keys

这两天在做一个feature

惊鸿一瞥 3389

oracle中 keys,案例:Oracle报错ORA-02266:unique/primary keys in table ....foreign keys

天萃荷净开发DBA反映在执行truncate清空一张表记录发现ORA-02266,进行模拟测试分析原因为存在主外键或索引导致1.truncate清空表报ORA-02266错误SQL> truncate table p;truncate table p*ERROR at line 1:ORA-02266: unique/primary keys in table referenced by e...

weixin_33483567的博客 1252

怎么php中primary keys,Creating Tables and Primary Keys

4.2.Creating Tables and Primary KeysThe schema in this section is referred to throughout the design chapters of this guide. Let's assume you are designing a flight reservation system. At its simplest...

weixin_28812943的博客 137

SET FOREIGN_KEY_CHECKS命令

ll写在前面正文OverviewWhen to UseFOREIGN_KEY_CHECKS Details 写在前面 刚在import xx.sql文件的时候,使用的是 Navicat Data Model 现在接触的项目是基本不用外键的(foreign key)的,可能单表设计,操作SQL更方便,尤其是JPA的存在,几乎都不用写sql的,但在表的设计使用若关联,即不使用外键约束表,只是在表里加...

诗和远方,任重道远 1万+

Partitioning Keys, Primary Keys, and Unique Keys

原文来自:http://dev.mysql.com/doc/refman/5.1/en/partitioning-limitations-partitioning-keys-unique-keys.html              This section discusses the relationship of partitioning keys with primary keys

tenfyguo的技术专栏 3409

A PRIMARY KEY must include all columns in the table’s partitioning function

这个是今天在学习 mysql 的建分区数据表时,遇到的一个问题,会提示: A PRIMARY KEY must include all columns in the table’s partitioning function 如果分区字段没有包含在主键字段内,如表A的主键为ID,分区字段为createtime ,按时间范围分区,执行会出上述的错误,代码如下: CREATE TABLE ...

Less Is More 1万+
上一篇: Adding Expressions, Default Values and Constraints to a Table
下一篇: .NET中正则表达式的一些语法概述
AllenTing
博客等级 码龄22年 2粉丝 16原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值