简体   繁体   English

创建表语句上的sql丢失或选项无效

[英]sql missing or invalid option on create table statement

I'm new to SQL, this segment should just make a few tables, right? 我是SQL的新手,该部分应该只创建几个表,对吗? I can't see anything wrong but Oracle says "missing or invalid option" on the line "CREATE TABLE Album" 我看不到任何错误,但是Oracle在“ CREATE TABLE Album”行上说了“ missing or invalid option”

CREATE TABLE Profile
(prid INTEGER,
first_name CHAR(20),
last_name CHAR(20),
year_of_birth INTEGER,
month_of_birth CHAR(9),
day_of_birth INTEGER,
gender CHAR(6),
PRIMARY KEY (prid))

CREATE TABLE Album
(aid INTEGER,
visible CHAR(20),
link CHAR(30),
create_time CHAR(30),
mod_time CHAR(30),
name CHAR(30),
owner_prid INTEGER,
PRIMARY KEY (aid),
FOREIGN KEY owner_prid REFERENCES Profile(prid))

cyberkiwi already answered your question about the syntax error. cyberkiwi已经回答了您有关语法错误的问题。

Since you're new to SQL, however, I wanted to comment on the DDL itself. 但是,由于您不熟悉SQL,所以我想对DDL本身进行评论。 In particular, it looks like you're using the wrong data types for a number of these columns-- that's going to come back to bite you. 特别是,您似乎为许多此类列使用了错误的数据类型,这会再次咬住您。

  • Do not use the CHAR data type unless you have an extremely compelling reason to do so 除非您有非常有说服力的理由,否则不要使用CHAR数据类型。

Many Oracle users will go further and suggest that you never ever use a CHAR data type. 许多Oracle用户会走得更远,建议您不要使用CHAR数据类型。 The basic problem with using CHAR is that the data is blank padded. 使用CHAR的基本问题是数据空白填充。 So if you store the word "Male" in the GENDER column and GENDER is a CHAR(6), Oracle has to store two additional spaces at the end of the string. 因此,如果将单词“ Male”存储在GENDER列中,并且GENDER是CHAR(6),则Oracle必须在字符串的末尾存储两个额外的空格。 That makes future comparison operations very perilous-- you have to make sure that CHAR comparison semantics are used rather than VARCHAR comparison semantics and that tends to get ugly. 这使得将来的比较操作非常危险-您必须确保使用CHAR比较语义而不是VARCHAR比较语义,并且这种做法会变得很丑陋。 Additionally, you're wasting space on disk and in memory to store those two additional spaces for no benefit. 此外,您浪费磁盘和内存上的空间来存储这两个额外的空间毫无益处。 All of your CHAR columns should really be VARCHAR2 您所有的CHAR列均应为VARCHAR2

  • Store dates as dates-- don't store date components and don't store dates as strings 将日期存储为日期-不存储日期成分也不将日期存储为字符串

Rather than storing a YEAR_OF_BIRTH , MONTH_OF_BIRTH , and DAY_OF_BIRTH , you're almost certainly better off with a single BIRTH_DATE column of type DATE where you store the birth date. 与其YEAR_OF_BIRTHMONTH_OF_BIRTHDAY_OF_BIRTH存储, MONTH_OF_BIRTH使用一个DATE类型的BIRTH_DATE列来存储出生日期,这无疑是更好的选择。 You can always extract the various date components if you want to find out what year someone was born. 如果您想了解某人出生的年份,则始终可以提取各种日期成分。 Storing the data as a DATE, though, will ensure that the date components themselves are valid (ie no typos where the month is listed as 'Febuary', no data quality issues where the month is sometimes 'Feb', sometimes 'February', and sometimes '2', no dates of February 30, etc.) Storing the data as a DATE gives the optimizer much more information to work with so it is more likely to generate the most efficient plan because it knows something about the data distribution. 不过,将数据存储为DATE可以确保日期部分本身有效(例如,没有错别字,其中月份被列为“ Febuary”,没有数据质量问题,月份有时为“ Feb”,有时为“ February”,有时是'2',没有2月30日的日期,等等。)将数据存储为DATE可以使优化程序获得更多的信息,因此更有可能生成最有效的计划,因为它对数据分布有所了解。 And you can use all the various date functions that Oracle provides. 您可以使用Oracle提供的所有各种日期函数。

By the same token, since CREATE_TIME and MOD_TIME are dates (an Oracle DATE always has a day and a time component), you should be storing them as DATEs (or TIMESTAMPs) rather than VARCHAR2's. 同样,由于CREATE_TIMEMOD_TIME是日期(Oracle DATE始终具有日期和时间成分),因此应将它们存储为DATE(或TIMESTAMP),而不是VARCHAR2。 That allows you to use date (or timestamp) functions, it ensures that the times are valid, it eliminates issues with different formats being stored in the same column, and it makes it much easier to use the various date functions. 这使您可以使用日期(或时间戳记)函数,确保时间有效,消除了将不同格式存储在同一列中的问题,并且使使用各种日期函数更加容易。

If you are using Oracle XE and the browser interface, you cannot run multi-line statements. 如果使用的是Oracle XE和浏览器界面,则不能运行多行语句。 Split them into two statements and run one, then clear text, paste the other, then run again. 将它们拆分为两个语句并运行一个,然后清除文本,粘贴另一个,然后再次运行。

Your 2nd block should be 您的第二块应该是

CREATE TABLE Album
(aid INTEGER,
visible CHAR(20),
link CHAR(30),
create_time CHAR(30),
mod_time CHAR(30),
name CHAR(30),
owner_prid INTEGER,
PRIMARY KEY (aid),
FOREIGN KEY (owner_prid) REFERENCES Profile(prid))

ie brackets around the field that forms part of the FK 即,围绕构成FK一部分的领域的括号

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

相关问题 “ ORA-00922:缺少或无效的选项” SQL创建表错误 - “ORA-00922: missing or invalid option” SQL create table error 为什么此CREATE TABLE语句导致“ORA-00922缺失或无效选项”? - Why does this CREATE TABLE statement cause “ORA-00922 missing or invalid option”? 在SQL Server 2005中向Create Table语句添加锁定选项 - adding lock option to Create Table statement in Sql Server 2005 SQL无效的ALTER TABLE选项 - SQL Invalid ALTER TABLE option 由于如果不存在,在创建表时缺少或无效的选项 - missing or invalid option , in creating table due to if not exists 在CREATE INDEX语句中指定的选项无效 - Invalid option specified in CREATE INDEX statement 为什么我在尝试创建表时遇到ORA-00922:丢失或无效选项? - Why am I getting ORA-00922: missing or invalid option while trying to create a table? ORA-00922 尝试为我的项目创建表时缺少或无效的选项 - ORA-00922 missing or invalid option while trying to create a table for my project 如果缺少表而不是抛出“无效的 object 名称”错误,如何强制 SQL 语句执行不同的 select? - How to force a SQL statement to do a different select if a table is missing instead of throwing the 'invalid object name' error? Oracle SQL - 无效的更改表选项 - Oracle SQL- Invalid Alter Table Option
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM