我刚开始使用 mysql - 因为我试图创建一个 table 我得到了下面的错误
I am new to using mysql - as i was trying to create a table i got the error below
它给我错误 -
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL
syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near 'varchar(100) NOT NULL,\n
Title varchar(100) NOT NULL, Firstname varchar...' at line 1")
con=pymysql.connect(host = "localhost", user = "root", password = "",database ="project1v2")
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS employees (Employeeid int(100) NOT NULL AUTO_INCREMENT,Emp ID varchar(100) NOT NULL,
Title varchar(100) NOT NULL, Firstname varchar(100) NOT NULL,
Middlename varchar(100) NOT NULL,Lastname varchar(100) NOT NULL,Dob varchar(100) NOT NULL,Nationality varchar(100) NOT NULL,
ni varchar(100) NOT NULL,Addres varchar(100) NOT NULL,Postcode varchar(100) NOT NULL,phonenumber varchar(100) NOT NULL,Email varchar(100) NOT NULL,
Wage varchar(100) NOT NULL,Passportnumber varchar(100) NOT NULL,Passportexpirydate varchar(100) NOT NULL,gender varchar(100) NOT NULL,
righttowork varchar(100) NOT NULL,Kinname varchar(100) NOT NULL,Kinrelation varchar(100) NOT NULL,Kinadress varchar(100) NOT NULL,
Kinphonenumber varchar(100) NOT NULL,Kinemail varchar(100) NOT NULL,Username varchar(100) NOT NULL, Passwor varchar(100) NOT NULL,
accesslevel varchar(100) NOT NULL,PRIMARY KEY (Employeeid)""")
con.commit()
con.close()
这里:
Emp ID varchar(100) NOT NULL,
标识符中不允许有空格,除非标识符被引用。
我会推荐:
EmpID varchar(100) NOT NULL,
如果你真的想要那个space:
`Emp ID` varchar(100) NOT NULL,
虽然我不建议使用这样的标识符;你需要在每次使用它时引用它,这很快就会变得乏味。
您不能将 space 赋给列名,如果您愿意,则必须将其括在引号中。
`emp id`
此外,您还缺少最后的右括号。
.. NULL,PRIMARY KEY (Employeeid) ) -- this is missing
它给我错误 -
pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'varchar(100) NOT NULL,\n
Title varchar(100) NOT NULL, Firstname varchar...' at line 1")
con=pymysql.connect(host = "localhost", user = "root", password = "",database ="project1v2")
cur = con.cursor()
cur.execute("""CREATE TABLE IF NOT EXISTS employees (Employeeid int(100) NOT NULL AUTO_INCREMENT,Emp ID varchar(100) NOT NULL,
Title varchar(100) NOT NULL, Firstname varchar(100) NOT NULL,
Middlename varchar(100) NOT NULL,Lastname varchar(100) NOT NULL,Dob varchar(100) NOT NULL,Nationality varchar(100) NOT NULL,
ni varchar(100) NOT NULL,Addres varchar(100) NOT NULL,Postcode varchar(100) NOT NULL,phonenumber varchar(100) NOT NULL,Email varchar(100) NOT NULL,
Wage varchar(100) NOT NULL,Passportnumber varchar(100) NOT NULL,Passportexpirydate varchar(100) NOT NULL,gender varchar(100) NOT NULL,
righttowork varchar(100) NOT NULL,Kinname varchar(100) NOT NULL,Kinrelation varchar(100) NOT NULL,Kinadress varchar(100) NOT NULL,
Kinphonenumber varchar(100) NOT NULL,Kinemail varchar(100) NOT NULL,Username varchar(100) NOT NULL, Passwor varchar(100) NOT NULL,
accesslevel varchar(100) NOT NULL,PRIMARY KEY (Employeeid)""")
con.commit()
con.close()
这里:
Emp ID varchar(100) NOT NULL,
标识符中不允许有空格,除非标识符被引用。
我会推荐:
EmpID varchar(100) NOT NULL,
如果你真的想要那个space:
`Emp ID` varchar(100) NOT NULL,
虽然我不建议使用这样的标识符;你需要在每次使用它时引用它,这很快就会变得乏味。
您不能将 space 赋给列名,如果您愿意,则必须将其括在引号中。
`emp id`
此外,您还缺少最后的右括号。
.. NULL,PRIMARY KEY (Employeeid) ) -- this is missing