成都网络公司-成都网站建设公司创新互联十余年经验成就非凡,专业从事成都网站建设、成都做网站,成都网页设计,成都网页制作,软文平台,一元广告等。十余年来已成功提供全面的成都网站建设方案,打造行业特色的成都网站建设案例,建站热线:18980820575,我们期待您的来电!
1,navicat外键怎么设置
打开我的navicat,然后找到我的teacher表,选中它,然后点击菜单栏上 在弹出的对话框中找到“Foreign Keys”,然后单机。2,SQL如何设置外键
可以在创建表的时候创建,也可以在创建表之后创建。创建表时创建:create table student(id int primary key,name char(4),dept char(9)sex char(4))create table grade(id int ,grade intconstraint id_fk foreign key (id) references student (id))或创建了两表之后再建alter table gradeadd constraint id_fk foreign key (id) references student (id)呵呵,希望能帮助你。首先在booktype表中定义主键:booktypeidcreate table booktype (booktypeid varchar(20) primary key,typename varchar(20));create table book (bookid int primary key, bookname varchar(20),booktypeid varchar(20) ,constraint fk foreign key(booktypeid) references booktype(booktypeid));3,如何设置外键约束
create table t1(A1 int primary key)create table t2(B1 int,B2 int)--对t2表的B2创建外键alter table t2 add constraint FK_B2_t1A1 foreign key(B2) references t1(A1)--注意:能作为一个表的外键关联字段(t1.A1)这个字段必须是主键或有唯一约束的(t1的A1必须是主键或者unique)create table t1(A1 int primary key)create table t2(B1 int,B2 int)--对t2表的B2创建外键(关联字段t1表的A1字段)alter table t2 add constraint FK_B2_t1A1 foreign key(B2) references t1(A1)--注意:能作为一个表的外键关联字段(t1.A1)这个字段必须是主键或有唯一约束的(t1的A1必须是主键或者unique)create table a ( a_id int primary key, ##主键 a_name varchar(2))create table b( b_id int , b_name varchar(2))##添加外键alter table b add constraint fk_b_a foreign key b_id references a(a_id)4,怎么给联合主键设置外键啊
GUI界面,先右键表B,表C,选择设计,然后选择表B字段b1设置主键,表C字段c1设置主键,然后保存关闭。右键表A,选择设计,按住shift然后选择a1,a2设置为联合主键,然后右键a1列,选择关系,添加后右面点击表和列规范,弹出界面,左边选择主键表主键列,右面选择本表字段a1即可。a2同样设置。语句的我知道用references就行 可是可视化的操作可以做到么?我正好有一个例子和你说的一样,请参考:CREATE TABLE [dbo].[ContractorMobileService]( [ContractorID] [int] NOT NULL, [MobileServiceID] [int] NOT NULL, [Charge] [money] NOT NULL, CONSTRAINT [PK_ContractorMobileService] PRIMARY KEY CLUSTERED ( [ContractorID] ASC, [MobileServiceID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]GOALTER TABLE [dbo].[ContractorMobileService] WITH NOCHECK ADD CONSTRAINT [FK_ContractorMobileService_Contractor] FOREIGN KEY([ContractorID])REFERENCES [dbo].[Contractor] ([ID])GOALTER TABLE [dbo].[ContractorMobileService] CHECK CONSTRAINT [FK_ContractorMobileService_Contractor]GOALTER TABLE [dbo].[ContractorMobileService] WITH NOCHECK ADD CONSTRAINT [FK_ContractorMobileService_MobileService] FOREIGN KEY([MobileServiceID])REFERENCES [dbo].[MobileService] ([ID])GOALTER TABLE [dbo].[ContractorMobileService] CHECK CONSTRAINT [FK_ContractorMobileService_MobileService]GO
5,如何创建外键是本身表的主键的外键
create table NewsType(id INT PRIMARY KEY ,parentId int references NewsType(id))其他字段你自己添吧 比如插入测试数据insert into NewsType values (1,1);--这个执行没问题insert into NewsType values (2,3);--会报错可以用数据库工具创建。具体方法如下:create table TabA (AF1 string ,AF2 int null,AF3 int null)create table TabB (BF1 string ,BF2 int )//创建constraint PK_AF1 primary key (AF1)constraint TabB primary key (BF1),constraint FK_Tab1_TAB2 foreign key (BF2)references TabA(AF1)具体例子如下:create table VAS_POSSTOR_DETAIL ( TEAMNO VARCHAR2(10) not null, POS_NO VARCHAR2(3) not null, ITEM_CODE VARCHAR2(10) not null, SORT_NO VARCHAR2(5) not null, INIT_QUANTITY NUMBER, STO_QUANTITY NUMBER, ORD_QUANTITY NUMBER, DEL_PRICE NUMBER(10,4), constraint PK_VAS_POSSTOR_DETAIL primary key (TEAMNO, POS_NO, ITEM_CODE), constraint FK_VAS_POSS_REFERENCE_VAS_POS foreign key (TEAMNO, POS_NO) references VAS_POSSTORAGE (TEAMNO, POS_NO)??创建表的语法-创建表格语法:create table 表名(???? 字段名1?? 字段类型(长度) 是否为空,???? 字段名2?? 字段类型???????????? 是否为空);-增加主键alter table 表名 add constraint 主键名 primary key (字段名1);-增加外键:alter table 表名???? add constraint 外键名 foreign key (字段名1)?????????? references 关联表 (字段名2);在建立表格时就指定主键和外键create table t_stu?? (
分享名称:外键怎么设置,navicat外键怎么设置
当前地址:https://www.cdcxhl.com/article16/icjpdg.html
成都网站建设公司_创新互联,为您提供定制网站、关键词优化、静态网站、软件开发、网站排名、网站导航
广告
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源:
创新互联