About 428,000 results
Open links in new tab
  1. sql server - T-SQL: Alter View - Stack Overflow

    Apr 1, 2014 · I have a view with a field for date as a varchar. I need to change it to date time using the following code. CONVERT(DATETIME, MyDates) This works fine when executing the view but I want to make the change permanent. I need some help with the syntax. So far I have. ALTER VIEW tableName CONVERT(DATETIME, MyDates) but it's obviously not working

  2. How to add new column in existing View in SQL-Server 2014 using …

    Sep 16, 2016 · you have to write the entire view again and just add or omit what you want to change. for example your view is now : create view myView as select field1 from table1 and now you want to add a field called New_Col than you write this : alter view myView as select field1, New_Col from table1

  3. How to make CREATE OR REPLACE VIEW work in SQL Server?

    Jul 18, 2015 · Then do a CREATE VIEW or ALTER VIEW depending on the result. IF OBJECT_ID('dbo.data_VVVV') IS NULL BEGIN CREATE VIEW dbo.data_VVVV AS SELECT VCV.xxxx, VCV.yyyy AS yyyy, VCV.zzzz AS zzzz FROM TABLE_A VCV END ELSE ALTER VIEW dbo.data_VVVV AS SELECT VCV.xxxx, VCV.yyyy AS yyyy, VCV.zzzz AS zzzz FROM …

  4. SQL Server: How to change name in a view? - Stack Overflow

    Sep 10, 2009 · You can use the ALTER VIEW statement something like this : ALTER VIEW dbo.myView AS SELECT foo FROM dbo.bar WHERE widget = 'foo' GO Reference on MSDN. To rename a view, use sp_rename System Stored Procedure : EXEC sp_rename 'dbo.myView', 'myNewViewName'

  5. How can I programmatically retrieve the alter view script for a view …

    Feb 18, 2011 · SELECT [definition] FROM sys.sql_modules WHERE [object_id] = OBJECT_ID('dbo.' + @ViewName); -- you don't need the type check if you are passing in the name of a view -- you can do the schema check using OBJECT_ID instead of an extra join -- if you want to reference system_sql_modules it is unlikely they -- will have dbo schema, if you …

  6. sql - Alter View within stored procedure - Stack Overflow

    Nov 3, 2016 · (Or even better begin terminating all your SQL Statements with semicolon as the alternative is deprecated). 2) Convert your alter view statement in a dynamic SQL string and execute it using sp_executesql as the ALTER VIEW statement must be the first one in the batch:

  7. SQL Server view takes a long time to alter but query itself finishes ...

    I am trying to alter an existing view in my SQL Server database. When I run the query by itself it finishes in about 4 seconds. When I run the alter statement with the same query it runs and never finishes (waited 15 minutes before stopping it). I do not have any indexes on the view I …

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

    Mar 2, 2016 · 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?

  9. Is there a way to retrieve the view definition from a SQL Server …

    Which version of SQL Server? For SQL Server 2005 and later, you can obtain the SQL script used to create the view like this: select definition from sys.objects o join sys.sql_modules m on m.object_id = o.object_id where o.object_id = object_id( 'dbo.MyView') and o.type = 'V' This returns a single row containing the script used to create/alter ...

  10. sql server - Add a new column to a view in SQL - Stack Overflow

    Apr 5, 2017 · You don't define the datatype of a column like that. You let the view use the underlying datatype like this. ALTER VIEW seat_availability AS SELECT flightid , flightdate , maxcapacity , bookedseats , availableseats FROM flight Or if you need to explicitly change the datatype you need to use CONVERT like this.

Refresh