3

我有这个 INSERT 语句:

INSERT INTO TBL_VIDEOS (
  TBL_VIDEOS.ID,
  TBL_VIDEOS.TITLE,
  TBL_VIDEOS.V_DESCRIPTION,
  TBL_VIDEOS.UPLOAD_DATE,
  TBL_VIDEOS.V_VIEWS,
  TBL_VIDEOS.USERNAME,
  TBL_VIDEOS.RATING,
  TBL_VIDEOS.V_SOURCE,
  TBL_VIDEOS.FLAG
) 
VALUES 
('Z8MTRH3LmTVm',
'Why Creativity is the New Economy',
'Dr Richard Florida, one of the world's leading ...
    this stuff does not matter, it is just wasted space',
CURRENT_TIMESTAMP,
0,
1,
0,
'http://www.youtube.com/watch?v=VPX7gowr2vE&feature=g-all-u'
,0)

但我收到此错误消息:

无效的对象名称“TBL_VIDEOS”

4

6 回答 6

2

TBL_VIDEOS从此部分中删除

INSERT INTO TBL_VIDEOS (
  TBL_VIDEOS.ID,
  TBL_VIDEOS.TITLE,
  TBL_VIDEOS.V_DESCRIPTION,
  TBL_VIDEOS.UPLOAD_DATE,
  TBL_VIDEOS.V_VIEWS,
  TBL_VIDEOS.USERNAME,
  TBL_VIDEOS.RATING,
  TBL_VIDEOS.V_SOURCE,
  TBL_VIDEOS.FLAG
) 

应该

INSERT INTO TBL_VIDEOS (
  ID,
  TITLE,
  V_DESCRIPTION,
  UPLOAD_DATE,
  V_VIEWS,
  USERNAME,
  RATING,
  V_SOURCE,
  FLAG
  )

你可以调查一下,任何你有类似内容的地方都world's leading experts应该改成world''s leading experts. 通过两次单引号,您正在转义单引号

于 2012-09-26T21:37:15.613 回答
2

您需要转义描述中的单引号:“世界领先的专家之一”

我不认为在这种情况下表的名称是一个问题,但它们是多余的。

以下将起作用:

create table TBL_VIDEOS (
ID nvarchar(100), TITLE nvarchar(100), V_DESCRIPTION nvarchar(2000), UPLOAD_DATE nvarchar(100), V_VIEWS nvarchar(100), USERNAME nvarchar(100), RATING nvarchar(100), V_SOURCE nvarchar(100), FLAG nvarchar(100)
)

INSERT INTO TBL_VIDEOS ( 

 TBL_VIDEOS.ID, TBL_VIDEOS.TITLE, TBL_VIDEOS.V_DESCRIPTION, TBL_VIDEOS.UPLOAD_DATE, TBL_VIDEOS.V_VIEWS, TBL_VIDEOS.USERNAME, TBL_VIDEOS.RATING, TBL_VIDEOS.V_SOURCE, TBL_VIDEOS.FLAG) 

VALUES 

('Z8MTRH3LmTVm', 'Why Creativity is the New Economy', 'Dr Richard Florida, one of the world' + CHAR(39) + 's leading experts on economic competitiveness, demographic trends and cultural and technological innovation shows how developing the full human and creative capabilities of each individual, combined with institutional supports such as commercial innovation and new industry, will put us back on the path to economic and social prosperity.

Listen to the podcast of the full event including audience Q&A: http://www.thersa.org/events/audio-and-past-events/2012/why-creativity-is-the-new-economy

Our events are made possible with the support of our Fellowship. Support us by donating or applying to become a Fellow.

Donate: http://www.thersa.org/support-the-rsa Become a Fellow: http://www.thersa.org/fellowship/apply', CURRENT_TIMESTAMP, 0, 1, 0, 'http://www.youtube.com/watch?v=VPX7gowr2vE&feature=g-all-u' ,0)
于 2012-09-26T21:43:09.457 回答
1

确保您添加了:USE Name_Of_Your_Database

于 2020-03-26T04:57:32.763 回答
0

在我的情况下,SQL Server 不喜欢对 COLUMNS 部分使用单引号,也不喜欢对 VALUES 部分使用双引号。

错误的

INSERT INTO [sample].[dbo].[users]
('username', 'password')
VALUES('hello', 'hello')

INSERT INTO [sample].[dbo].[users]
("username", "password")
VALUES("hello", "world")

正确的

INSERT INTO [sample].[dbo].[users]
("username", "password")
VALUES('hello', 'world')
于 2020-08-11T00:52:10.557 回答
0

尝试硬刷新 Ctrl+Shift+R

您可能不得不允许 SSMS 在刚刚创建表后识别它。

于 2021-07-26T17:55:03.230 回答
0

在我的情况下,SQL 在尝试使用以下语句插入值时给出了“无效的对象名称”错误消息:

IF NOT EXISTS (SELECT 1 FROM [DatabaseName].[SchemaName].[TableName] 
WITH (NOLOCK) WHERE col1 = val1)
BEGIN
  INSERT INTO [SchemaName].[TableName] (col1, col2,col3) 
  Values(val1, val2, val3)
END

为避免此错误,我使用以下语句将记录插入表中:

IF NOT EXISTS (SELECT 1 FROM [DatabaseName].[SchemaName].[TableName] 
WITH (NOLOCK) WHERE col1 = val1)
BEGIN
   INSERT INTO SchemaName.TableName (col1, col2,col3) 
   Values(val1, val2, val3)
END
于 2022-02-11T08:59:52.037 回答