可以更改 SQL Server 2000 视图中的列长度吗?

发布于 2024-12-25 05:30:09 字数 175 浏览 3 评论 0原文

不确定这是否允许,但如果允许,有人可以告诉我 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

水水月牙 2025-01-01 05:30:09

不直接。

这是从列表达式自动导出的。不过,您可以将 View SELECT 列表中的表达式CAST 转换为特定的数据类型。

Not directly.

This is derived automatically from the column expression. You can CAST the expression in the View SELECT list to a particular datatype though.

↙温凉少女 2025-01-01 05:30:09

您需要更改基础表中的列长度,或者更改形成视图的 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.

感性 2025-01-01 05:30:09

视图是查看其他表中数据的方法;通常,数据只是基础表中的任何内容,因此您需要更改那里的列。

但是,您可以拥有执行诸如cast()或convert()之类的操作的视图;这些通常是一个坏主意,因为每次使用视图时都需要重新获取数据,而这些操作会增加开销。在视图的设计中,您可以决定转换为另一种数据类型,或者进行任何您想要的转换 - 但它有开销,并且不会改变原始数据。

如果您知道当前视图选择什么,则可以使用类似以下内容的内容:

Alter view Viewname[cloumn] as Select cast(original_data as varchar(n)) from Original_Table

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:

Alter view Viewname[cloumn] as Select cast(original_data as varchar(n)) from Original_Table
薄荷→糖丶微凉 2025-01-01 05:30:09

我刚刚遇到了同样的情况。我所做的是:

  1. 更改视图查看的表中的列大小。

  2. 创建一个脚本来重新创建视图(如果您还没有)。

  3. 删除视图

  4. 使用脚本重新创建视图。

之后,视图中的列大小与我对基础表所做的更改相同。

I just ran into the same situation. What I did was:

  1. Change the column size in the table that the view looks at.

  2. Create a script to recreate the view (if you don't already have one).

  3. Delete the view

  4. 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.

谁许谁一生繁华 2025-01-01 05:30:09

您无法更改视图中的列大小,因为视图是从其他表派生的。因此,如果需要更改列大小,请更改表的列大小。要更改列大小,请使用 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.

愁杀 2025-01-01 05:30:09

如果视图中显示的长度与基础表不匹配,则删除并重新创建视图。

使用类似的方法来调查表和视图中的列长度

SELECT o.[name], *
FROM sys.all_columns c
INNER JOIN sys.objects o on o.[object_id]=c.[object_id]
WHERE c.[name] = 'OML'
-- AND c.[max_length]=11
ORDER BY O.[name];

要获取删除和创建 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

SELECT o.[name], *
FROM sys.all_columns c
INNER JOIN sys.objects o on o.[object_id]=c.[object_id]
WHERE c.[name] = 'OML'
-- AND c.[max_length]=11
ORDER BY O.[name];

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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文