我在sql server中有一列需要选择,我不能选择,但似乎存在。它是只读列还是其他问题?希望我在这里添加了足够的信息,并将我的列和表的名称更改为通用名称。如何选择一个不可选的列
SELECT t.name as TName, c.name AS ColName
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE upper(c.name) like '%MY_COLUMN_NAME%'
TName ColName
------ -----------
My_Table My_Column
但是当我尝试选择它时,它说它不存在。有没有解决方法?
select My_Column from My_Table
Msg 207, Level 16, State 1, Line 9
Invalid column name 'My_Column'.
当我尝试了所有的信息,我得到这个:
SELECT t.name as TName, c.name AS ColName, t.*, c.*
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE upper(c.name) like '%My_Column%'
TName ColName name object_id principal_id schema_id parent_object_id type type_desc create_date modify_date is_ms_shipped is_published is_schema_published lob_data_space_id filestream_data_space_id max_column_id_used lock_on_bulk_load uses_ansi_nulls is_replicated has_replication_filter is_merge_published is_sync_tran_subscribed has_unchecked_assembly_data text_in_row_limit large_value_types_out_of_row is_tracked_by_cdc lock_escalation lock_escalation_desc is_filetable object_id name column_id system_type_id user_type_id max_length precision scale collation_name is_nullable is_ansi_padded is_rowguidcol is_identity is_computed is_filestream is_replicated is_non_sql_subscribed is_merge_published is_dts_replicated is_xml_document xml_collection_id default_object_id rule_object_id is_sparse is_column_set
-------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------------------------------------- ----------- ------------ ----------- ---------------- ---- ------------------------------------------------------------ ----------------------- ----------------------- ------------- ------------ ------------------- ----------------- ------------------------ ------------------ ----------------- --------------- ------------- ---------------------- ------------------ ----------------------- --------------------------- ----------------- ---------------------------- ----------------- --------------- ------------------------------------------------------------ ------------ ----------- -------------------------------------------------------------------------------------------------------------------------------- ----------- -------------- ------------ ---------- --------- ----- -------------------------------------------------------------------------------------------------------------------------------- ----------- -------------- ------------- ----------- ----------- ------------- ------------- --------------------- ------------------ ----------------- --------------- ----------------- ----------------- -------------- --------- -------------
My_Table My_Column My_Table 1223935682 NULL 20 0 U USER_TABLE 2014-02-19 10:35:44.537 2017-02-11 12:48:13.037 0 0 0 1 NULL 39 0 1 0 0 0 0 0 0 0 0 0 TABLE 0 1223935682 My_Column 7 104 376 1 1 0 NULL 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
(影响1行(S))
当你执行“SELECT * FROM表”语句你得到了什么结果呢?它是否显示结果中的列? – Shell
这会返回多少行? select * from sys.tables where name ='My_Table' –
这是一个棘手的服务器b/c他们使用服务器对象来连接另一个数据库,他们没有将所有模式添加到连接/链接的数据库。所以它只为dbo模式返回一行。 – RetroCoder