INSERT INTO sql server错误:无效的对象名称

时间:2012-09-26 21:33:07

标签: sql sql-server

我有这个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'

5 个答案:

答案 0 :(得分: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。通过两次单引号,你就可以逃避单引号

答案 1 :(得分: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)

答案 2 :(得分:0)

确保您添加了: 使用Name_Of_Your_Database

答案 3 :(得分: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')

答案 4 :(得分:-1)

尝试硬刷新 Ctrl+Shift+R

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