在javascript('dbo.index')

我必须从我的节点js express应用程序中的SQL Server中读取名为dbo.Index的表,但是该表失败并且什么也不返回。

这是我的代码:

app.get('/getData',(req,res,next) => {
    const config = {
        user: 'sa',password: '12345',server: 'localhost',database: 'myDB'
    }
    const pool = new sql.ConnectionPool(config)

    pool.connect(err => {
        if (err) console.log(err)
        console.log('connected.')

        const request = new sql.Request(pool)
        request.query(`SELECT * FROM dbo.Index`,(error,recordSet) => {
            if (err) console.log(error)
            res.send(recordSet)
        })
    })

})

我已经测试了这段代码,并且可以与其他表一起很好地工作,但是使用特定名称dbo.Index时,它将失败。

我有必要阅读它,并且我不能更改表名(没有权限)。

我使用 node-mssql 软件包来连接到数据库。

iCMS 回答:在javascript('dbo.index')

INDEXReserved word,因此您需要将其用方括号括起来,如下所示:

SELECT * FROM [dbo].[Index]

通常最好避免在表名或列名中使用保留字,因为这样容易导致混乱,错误和错误。

本文链接:https://www.f2er.com/2116399.html

大家都在问