Cannot find user defined datatype 'empnum' in SQL Server 2014

别说谁变了你拦得住时间么 提交于 2020-01-04 02:57:08

问题


When I run the following query in SQL Server 2014 to create a temporary table:

CREATE TABLE #temp 
(   
    location char(16) null, 
    location_desc varchar(25) null, 
    Emp_Num EMPNUM null
)

I receive the error:

Cannot find the data type empnum.

empnum is a user-defined data type. But the same user-defined data type is working fine in other stored procedures.

Why am I receiving this error?


回答1:


It looks like user defined types are defined at database level, not instance level, so they must be defined for each database. For temporary tables, that means tempdb - creation query should be something like the following:

exec tempdb.sys.sp_executesql N'CREATE type EMPNUM ...';

A discussion regarding this subject can be found here.




回答2:


If using the tempdb, you need to define the type in the model database since types are at the db level. If the type has been defined for the model then you may still have permissions issues if the model db hasn't been given the db_ddladmin role.

The model db is a template for all new db's, tempdb does not persist between restarts, it is created new each startup.



来源:https://stackoverflow.com/questions/36003051/cannot-find-user-defined-datatype-empnum-in-sql-server-2014

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!