简体   繁体   English

尝试在sql oracle 11g中创建表

[英]Try to create a table in sql oracle 11g

I'm trying to create a table, but it kept giving me error msg "invalid identifier", I searched again and again, couldn't figure out what's wrong with my code..... please help.....here is my code.. 我正在尝试创建一个表,但是它一直给我错误消息味精“无效标识符”,我反复搜索,无法弄清楚我的代码出了什么问题.....请帮助.....这里是我的代码。

create table ownership
(
   oID number not null,
   dID number not null,
   start date,
   end date,
   primary key (oID,dID)
   foreign key (oID) references owner(oID),
   foreign key (dID) references dogs(dID)
);

I imported dogs table from nyc open data, and I also created owner table.....The table names are not wrong, I checked over and over again, the oID in table owner is primary key, so does dID in table dogs..... I tried to delete not null constraint, same error msg, I tried to put constraint pk_ownership before primary key, still get the same error msg.....I really couldn't figure out why... This is for a school project, I'm super super new to sql, it's my 2nd day doing sql......if my question is stupid, please bare me.....Thank you! 我从nyc打开数据导入了dogs表,并且还创建了所有者表.....表名没有错,我一遍又一遍地检查,表所有者中的oID是主键,表狗中的dID也是如此。 ....我试图删除不为null的约束,错误消息为msg,我试图将pk_ownership约束放在主键之前,但仍然收到相同的错误消息.....我真的不知道为什么...这是对于一个学校项目,我是sql的超级新手,这是我做sql的第二天……如果我的问题很愚蠢,请裸露我.....谢谢!

You have two major errors: 您有两个主要错误:

  • you are missing a comma (on the primary) 您缺少逗号(在主数据库上)
  • start is a reserved word start是保留字

end is also a keyword, so I would discourage using that as well. end也是一个关键字,因此我也建议不要使用它。

I would suggest something like: 我建议类似的东西:

create table ownership (
   oID number not null,
   dID number not null,
   ownership_start date,
   ownership_end date,
   primary key (oID, dID),
   foreign key (oID) references owner(oID),
   foreign key (dID) references dogs(dID)
);

In Oracle start is a reserved word. 在Oracle中, start是保留字。 You can use it if you quote it, as in: 如果引用它,则可以使用它,如下所示:

create table ownership
(
   oID number not null,
   dID number not null,
   "start" date,
   end date,
   primary key (oID,dID),
   foreign key (oID) references owner(oID),
   foreign key (dID) references dogs(dID)
);

Or... you can simply use a different name such as start_ownership . 或者...您可以简单地使用其他名称,例如start_ownership

PS: You also had a minor syntax error. PS:您也有一个较小的语法错误。 You had forgotten a comma at the end of the primary key definition. 您忘记了主键定义末尾的逗号。

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

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