Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change the datatype of a column in a view?

Usually I run a script like this:

ALTER TABLE [TABLE]
ALTER COLUMN [Column] NVARCHAR(40);

The result is that the field in the table gets converted to nvarchar. But what is the syntax for doing the same thing for a view? Or is that even possible?

like image 493
Zolt Avatar asked May 22 '12 23:05

Zolt


People also ask

How do I change the datatype of a column in view?

Change data types in Design viewLocate the field that you want to change, and select a new data type from the list in the Data Type column. Save your changes.

Can we change data in a view SQL?

To modify table data through a view. In Object Explorer, expand the database that contains the view and then expand Views. Right-click the view and select Edit Top 200 Rows. You may need to modify the SELECT statement in the SQL pane to return the rows to be modified.

Can we alter column in view?

The altered view replaces the existing view, so you cannot modify specific columns in a view.

Can we update data through view?

We cannot insert or update data using view. The view is a virtual table. We can do those action, but it's effect on real table data too. View is like a virtual table which enable us to get information of multiple tables.


1 Answers

Sure

CREATE VIEW AView
AS
SELECT CAST(title AS char(50))
FROM titles

So check out CAST and also CONVERT on the msdn pages for full info

like image 140
buckley Avatar answered Oct 14 '22 11:10

buckley