可以更改 SQL Server 2000 视图中的列长度吗?
不确定这是否允许,但如果允许,有人可以告诉我 T-SQL 是什么吗?我已尝试以下方法但无济于事。
alter [View_Name]
alter column [Coln_Name] [New size/length] not null
GO
任何帮助表示赞赏。谢谢!
Not sure if this is even allowed, but if so, can someone tell me what the T-SQL is? I've tried the following but to no avail.
alter [View_Name]
alter column [Coln_Name] [New size/length] not null
GO
Any help is appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不直接。
这是从列表达式自动导出的。不过,您可以将 View
SELECT
列表中的表达式CAST
转换为特定的数据类型。Not directly.
This is derived automatically from the column expression. You can
CAST
the expression in the ViewSELECT
list to a particular datatype though.您需要更改基础表中的列长度,或者更改形成视图的 SELECT 语句以将列转换或转换为不同长度的数据类型。
You would need to change the column length in the underlying table, or to change the SELECT statement forming the view to CAST or CONVERT the column to a different length data type.
视图是查看其他表中数据的方法;通常,数据只是基础表中的任何内容,因此您需要更改那里的列。
但是,您可以拥有执行诸如cast()或convert()之类的操作的视图;这些通常是一个坏主意,因为每次使用视图时都需要重新获取数据,而这些操作会增加开销。在视图的设计中,您可以决定转换为另一种数据类型,或者进行任何您想要的转换 - 但它有开销,并且不会改变原始数据。
如果您知道当前视图选择什么,则可以使用类似以下内容的内容:
Views are ways to see data in other tables; typically the data is simply whatever is in the underlying table, so you would need to change the column there.
However, you can have views that do things like cast() or convert(); these are typically a bad idea, becuase the data needs to be re-fetched every time the view is used, and these operations add overhead. In the design of the view, you can decide to cast as another data type, or do any transformation you would like - but it has overhead, and will not alter the original data.
If you know what the current view selects, you can use something like:
我刚刚遇到了同样的情况。我所做的是:
更改视图查看的表中的列大小。
创建一个脚本来重新创建视图(如果您还没有)。
删除视图
使用脚本重新创建视图。
之后,视图中的列大小与我对基础表所做的更改相同。
I just ran into the same situation. What I did was:
Change the column size in the table that the view looks at.
Create a script to recreate the view (if you don't already have one).
Delete the view
Use the script to recreate the view.
After that the column sizes in the view were the same as the changes I made to the underlying table.
您无法更改视图中的列大小,因为视图是从其他表派生的。因此,如果需要更改列大小,请更改表的列大小。要更改列大小,请使用 ALTER TABLE 作为:
ALTER TABLE [Table_Name]
ALTER COLUMN [Column_Name] Data_Type(Size)
更改列大小后,您可能需要删除视图并再次重新创建它。
You can not alter the column size in a view as a view is derived from other table. So if you need to change the column size, change the column size of the table. To change the column size use ALTER TABLE as :
ALTER TABLE [Table_Name]
ALTER COLUMN [Column_Name] Data_Type(Size)
After changing the column size you might need to drop the view and recreate it again.
如果视图中显示的长度与基础表不匹配,则删除并重新创建视图。
使用类似的方法来调查表和视图中的列长度
要获取删除和创建 sql,我使用 SSMS 并右键单击上下文菜单(在对象资源管理器中的视图上),然后转到“脚本查看为”和“删除并创建到'。
If the length shown in the view doesn't match the underlying table then drop and recreate the view.
Use something like this to investigate the column lengths in the table and view
To get the Drop and Create sql I use SSMS and right click context menu (on the view in the Object Explorer), then go to 'Script View as', and 'DROP And CREATE To'.