select有错?
#创建连接对象
import pymssql
#创建数据库连接对象,与数据库建立连接
conn = pymssql.connect(
host="localhost", # 数据库主机地址
user="sa", # 数据库用户名
password="123456", # 数据库密码
database="User-sql",
charset='utf8',
tds_version="7.0"
)
print(conn)
#创建游标对象
mycursor = conn.cursor()
print(mycursor)
sql ='SELECT userid,username FROM user;'
mycursor.execute(sql)
rs = mycursor.fetchall()
print(rs)
mycursor.close()
conn.close()
报这样的错是什么意思求大神指教
Traceback (most recent call last):
File "src\pymssql.pyx", line 448, in pymssql.Cursor.execute
File "src\_mssql.pyx", line 1064, in _mssql.MSSQLConnection.execute_query
File "src\_mssql.pyx", line 1095, in _mssql.MSSQLConnection.execute_query
File "src\_mssql.pyx", line 1228, in _mssql.MSSQLConnection.format_and_run_query
File "src\_mssql.pyx", line 1639, in _mssql.check_cancel_and_raise
File "src\_mssql.pyx", line 1683, in _mssql.maybe_raise_MSSQLDatabaseException
_mssql.MSSQLDatabaseException: (156, b"Incorrect syntax near the keyword 'user'.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\python-3.6.0\Tools\runoob\consql\test.py", line 22, in <module>
mycursor.execute(sql.encode(encoding='utf_8', errors='strict'))
File "src\pymssql.pyx", line 468, in pymssql.Cursor.execute
pymssql.OperationalError: (156, b"Incorrect syntax near the keyword 'user'.DB-Lib error message 20018, severity 15:\nGeneral SQL Server error: Check messages from the SQL Server\n")