我刚刚创建的表上的 MS SQL 错误“对象名称无效”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3309365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MS SQL Error "Invalid object name" on table I just created
提问by JSJoy
I get an
我得到一个
invalid object name
无效的对象名称
error when I try to insert records into a table that I just created.
当我尝试将记录插入到我刚刚创建的表中时出错。
I am using Microsoft SQL 2000
. I am testing all of this on the super user account, so there are no permissions issues.
我正在使用Microsoft SQL 2000
. 我正在超级用户帐户上测试所有这些,因此没有权限问题。
Create the table:
创建表:
CREATE TABLE [table_test2] (
[User 4] [varchar] (10) NULL ,
[User 3] [varchar] (10) NULL ,
[User 2] [varchar] (10) NULL ,
[User 1] [varchar] (10) NULL ,
[Spouse] [varchar] (10) NULL ,
[Sensitivity] [varchar] (10) NULL ,
[Referred By] [varchar] (10) NULL ,
[Profession] [varchar] (10) NULL ,
[Private] [varchar] (10) NULL ,
[Priority] [varchar] (10) NULL ,
[Other Address PO Box] [varchar] (10) NULL ,
[Organizational ID Number] [varchar] (10) NULL ,
[Office Location] [varchar] (10) NULL ,
[Notes] [varchar] (133) NULL ,
[Mileage] [varchar] (10) NULL ,
[Manager's Name] [varchar] (10) NULL ,
[Location] [varchar] (10) NULL ,
[Language] [varchar] (10) NULL ,
[Keywords] [varchar] (10) NULL ,
[Internet Free Busy] [varchar] (10) NULL ,
[Initials] [varchar] (10) NULL ,
[Home Address PO Box] [varchar] (10) NULL ,
[Hobby] [varchar] (10) NULL ,
[Government ID Number] [varchar] (10) NULL ,
[Gender] [varchar] (16) NULL ,
[E-mail 3 Display Name] [varchar] (10) NULL ,
[E-mail 3 Type] [varchar] (10) NULL ,
[E-mail 3 Address] [varchar] (10) NULL ,
[E-mail 2 Display Name] [varchar] (10) NULL ,
[E-mail 2 Type] [varchar] (10) NULL ,
[E-mail 2 Address] [varchar] (10) NULL ,
[E-mail Display Name] [varchar] (38) NULL ,
[E-mail Type] [varchar] (10) NULL ,
[E-mail Address] [varchar] (38) NULL ,
[Directory Server] [varchar] (10) NULL ,
[Children] [varchar] (10) NULL ,
[Categories] [varchar] (10) NULL ,
[Business Address PO Box] [varchar] (10) NULL ,
[Birthday] [varchar] (10) NULL ,
[Billing Information] [varchar] (10) NULL ,
[Assistant's Name] [varchar] (10) NULL ,
[Anniversary] [varchar] (10) NULL ,
[Account] [varchar] (10) NULL ,
[Telex] [varchar] (10) NULL ,
[TTY/TDD Phone] [varchar] (10) NULL ,
[Radio Phone] [varchar] (10) NULL ,
[Primary Phone] [varchar] (10) NULL ,
[Pager] [varchar] (10) NULL ,
[Other Phone] [varchar] (10) NULL ,
[Other Fax] [varchar] (10) NULL ,
[Mobile Phone] [varchar] (19) NULL ,
[ISDN] [varchar] (10) NULL ,
[Home Phone 2] [varchar] (10) NULL ,
[Home Phone] [varchar] (10) NULL ,
[Home Fax] [varchar] (10) NULL ,
[Company Main Phone] [varchar] (10) NULL ,
[Car Phone] [varchar] (10) NULL ,
[Callback] [varchar] (10) NULL ,
[Business Phone 2] [varchar] (10) NULL ,
[Business Phone] [varchar] (19) NULL ,
[Business Fax] [varchar] (19) NULL ,
[Assistant's Phone] [varchar] (10) NULL ,
[Other Country/Region] [varchar] (10) NULL ,
[Other Postal Code] [varchar] (10) NULL ,
[Other State] [varchar] (10) NULL ,
[Other City] [varchar] (10) NULL ,
[Other Street 3] [varchar] (10) NULL ,
[Other Street 2] [varchar] (10) NULL ,
[Other Street] [varchar] (10) NULL ,
[Home Country/Region] [varchar] (10) NULL ,
[Home Postal Code] [varchar] (10) NULL ,
[Home State] [varchar] (10) NULL ,
[Home City] [varchar] (10) NULL ,
[Home Street 3] [varchar] (10) NULL ,
[Home Street 2] [varchar] (10) NULL ,
[Home Street] [varchar] (10) NULL ,
[Business Country/Region] [varchar] (29) NULL ,
[Business Postal Code] [varchar] (10) NULL ,
[Business State] [varchar] (10) NULL ,
[Business City] [varchar] (17) NULL ,
[Business Street 3] [varchar] (10) NULL ,
[Business Street 2] [varchar] (10) NULL ,
[Business Street] [varchar] (30) NULL ,
[Job Title] [varchar] (10) NULL ,
[Department] [varchar] (10) NULL ,
[Company] [varchar] (34) NULL ,
[Suffix] [varchar] (10) NULL ,
[Last Name] [varchar] (16) NULL ,
[Middle Name] [varchar] (10) NULL ,
[First Name] [varchar] (10) NULL ,
[Title] [varchar] (10) NULL
)
No errors creating the table!!
创建表没有错误!!
I can select from the table:
我可以从表中选择:
select * from table_test2
But when I try to insert, I get an error that the object is not fonud:
但是当我尝试插入时,我收到一个错误,指出对象不是 fonud:
insert into table_test2
('User 4', 'User 3', 'User 2')
values
('a','b','c')
Returns error:
返回错误:
Server: Msg 208, Level 16, State 3, Line 1 Invalid object name 'table_test'.
服务器:消息 208,级别 16,状态 3,第 1 行 无效的对象名称“table_test”。
采纳答案by Martin Smith
They don't have the same name though. The one you have created has a 2
suffix.
虽然他们没有相同的名字。您创建的那个有一个2
后缀。
CREATE TABLE [table_test2]
And
和
select * from table_test
If you are sure you weren't making a similar error with your select/insert statements I would suggest running the following.
如果您确定您的 select/insert 语句没有出现类似的错误,我建议您运行以下命令。
select * from
sysobjects /*For SQL Server 2000*/
where name like 'table_test%'
Additionally your insert
statement looks dodgy. I think you would need square brackets or double quotes not single quotes. I'm not sure if that could produce the error you were seeing.
此外,您的insert
声明看起来很狡猾。我认为您需要方括号或双引号而不是单引号。我不确定这是否会产生您看到的错误。
insert into table_test
([User 4], [User 3], [User 2])
values
('a','b','c')
回答by Kieren Johnstone
Are you certain you are using the correct database? Try using the USE
statement right before each, or prefixing the table with the name of the database, for example:
您确定您使用的是正确的数据库吗?尝试USE
在每个语句之前使用语句,或者在表前加上数据库名称,例如:
CREATE TABLE mydatabase..table_name ...
INSERT INTO mydatabase..table_name ...
The '..' prefix can be used so you don't need to specify the schema (e.g. dbo
).
可以使用 '..' 前缀,因此您无需指定架构(例如dbo
)。
Hope that helps.
希望有帮助。
回答by JSJoy
Syntax error. Need to wrap the insert statement column list with brackets rather than quotes:
语法错误。需要用括号而不是引号包裹插入语句列列表:
this would be the proper syntax:
这将是正确的语法:
insert into table_test2
([User 4], [User 3], [User 2])
values
('a','b','c')
回答by DoubleJ92
In your CREATE TABLE statement, the name of the table is table_test2
在您的 CREATE TABLE 语句中,表的名称是 table_test2