简体   繁体   English

SQL查询更改表

[英]Sql query to alter table

I have two tables miusernames with columns where UserNamesID is the primary key for table miusernames.. 我有两个带有列的表miusername ,其中UserNamesID是表miusername的主键。

UserNamesID       UserName  
1                  senthil

2                  robert

and miemailids with columns where Emailid is the primary key for table miemailids .. 和带有列的miemailids ,其中Emailid是表miemailids的主键。

Emailid   UserNamesID  
1             2

I forgot to create column UserNamesID in table miemailids as foreign key relationship with parent table miusernames .. I need values of column UserNamesID in table miemailids should not be the values other than values in UserNamesID column in parent table miusernames. 我忘记在表miemailids中创建列UserNamesID作为与父表miusernames的外键关系..我需要表miemailids中UserNamesID列的值不应是父表miusernames中UserNamesID列中的值。

I need help in alter table miemailids as adding foreign key relationship for column UserNamesID with parent table miusernames.. Help me with the query to alter table..I feel good if i get exact query.. thanx in advance 我需要更改表miemailids的帮助,因为需要为带有父表miusernames的列UserNamesID添加外键关系。帮助我进行更改表的查询。如果提前获得确切的查询,我会感觉很好。

ALTER TABLE miemailids
ADD FOREIGNKEY (UserNamesID) REFERENCES miusernames(UserNamesID)

should do it if you are on mysql and MSSQL 如果您使用的是mysql和MSSQL,则应该这样做

ALTER TABLE miemailids
ADD (CONSTRAINT fk_UserNamesID) FOREIGN KEY (UserNamesID) REFERENCES miusernames(UserNamesID);

should do it on Oracle 应该在Oracle上做到

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM