我有一项家庭作业,正在努力找出我的错误。我正在MySQL中创建一个表,并且是这方面的初学者。请给出建议!!
Create table computer_inventory
(
assetnumber int(10) not null default “0”,
manufacturer varchar(15) not null default ‘ ‘,
originalcost decimal(12,2) not null default “0”,
currentvalue decimal(12,2) not null default ‘0’,
boughtfrom varchar(20) not null default ‘ ‘,
instock tinyint(1) not null default ‘ ‘,
currentuser varchar(20) not null default ‘ ‘,
userphonenum varchar(13) not null default ‘ ‘,
boughtdate datatime not null default ‘ ‘
);再说一次,我是新来的,所以可能会有很多错误。
**EDIT:**
Create table computer_inventory (
assetnumber int(10) not null default 0,
manufacturer varchar(15) not null default ‘ ‘,
originalcost decimal(12,2) not null default 0,
currentvalue decimal(12,2) not null default 0,
boughtfrom varchar(20) not null default ‘ ‘,
instock tinyint(1) not null default 0,
currentuser varchar(20) not null default ‘ ‘,
userphonenum varchar(13) not null default ‘ ‘,
boughtdate datetime not null default ‘0000-00=00’
);我正在使用MySQL 5.6。错误是“错误1064 (42000):您的SQL语法有错误;请检查与MySQL服务器版本相对应的手册,以获得正确的语法,使用接近‘的正确语法,原始成本小数点(12,2)非空默认值0,当前值小数(1’在第2行)。”
发布于 2013-11-10 01:46:24
有几件事不对..。datetime拼错了。一些默认值也是列的错误数据类型。
Create table computer_inventory
(
assetnumber int(10) not null default 0,
manufacturer varchar(15) not null default '',
originalcost decimal(12,2) not null default 0,
currentvalue decimal(12,2) not null default 0,
boughtfrom varchar(20) not null default '',
instock tinyint(1) not null default 0,
currentuser varchar(20) not null default '',
userphonenum varchar(13) not null default '',
boughtdate datetime not null default '0000-00-00'
);下一次遇到这样的问题时,您可以这样做:首先尝试使用一两列来创建表,如果这些行没有错误,那么删除该表,再用几个列重新创建它。如果您得到错误,这将使它更容易分离准确的部分是不正确的。当我测试这个的时候,我发现了错误的默认值之类的错误.例如instock tinyint(1) not null default ' ',它无法工作,因为您试图将空字符串设置为整数列。它不起作用。对于datetime默认值,我必须在google上查找它,以查看适当的空日期值是什么。其中一些也是尝试和错误的,比如移除后排,用普通引号替换。
编辑:这对我来说没有错误..。我正在用sql小提琴测试它,它被设置为MySQL 5.5.31。告诉我您所得到的确切错误(除非您告诉我们错误说了什么,我无法猜测)以及您正在使用的DB及其版本,否则我们无法帮助您。
这是基于您的编辑以上。您将0000-00-00'输入为0000-00=00',需要使用普通单引号而不是回勾(我认为?)。
Create table computer_inventory (
assetnumber int(10) not null default 0,
manufacturer varchar(15) not null default ' ',
originalcost decimal(12,2) not null default 0,
currentvalue decimal(12,2) not null default 0,
boughtfrom varchar(20) not null default ' ',
instock tinyint(1) not null default 0,
currentuser varchar(20) not null default ' ',
userphonenum varchar(13) not null default ' ',
boughtdate datetime not null default '0000-00-00'
);https://stackoverflow.com/questions/19885296
复制相似问题