How to Modify Names in an SQL View?

  • Thread starter WWGD
  • Start date
  • Tags
    Sql
In summary, to change names in an SQL view, you can use the ALTER VIEW command. This allows you to modify existing views by changing the name of the view or its columns. You can also delete the view and recreate it with the desired changes. Some helpful resources for this process include the ALTER command and the ALTER VIEW statement.
  • #1
WWGD
Science Advisor
Gold Member
7,309
11,118
Does anyone know how to change names in an SQL view (i.e., a sort of a subset of a database. We may create it by saving a query and then doing a query on this saved query )?
Thanks.
 
Technology news on Phys.org
  • #3
Hi, thanks. It is kind of hard for me to export the database here. I am interested in changing the name of a field within a view in SQL.
Thanks for the links.
 
  • #4
You need to use 'ALTER VIEW' e.g.

ALTER VIEW HumanResources.EmployeeHireDate
AS
SELECT p.FirstName, p.LastName, e.HireDate
FROM HumanResources.Employee AS e JOIN Person.Person AS p
ON e.BusinessEntityID = p.BusinessEntityID
WHERE HireDate < CONVERT(DATETIME,'20020101',101) ;
GO
 
  • #5
Thanks, avarma^2
 

FAQ: How to Modify Names in an SQL View?

1. How do I change the name of a column in an SQL view?

To change the name of a column in an SQL view, you can use the AS keyword followed by the new column name after the original column name in the SELECT statement. For example, SELECT column_name AS new_column_name FROM table_name;

2. Can I change the name of a table in an SQL view?

Yes, you can change the name of a table in an SQL view by using the RENAME command. For example, RENAME TABLE old_table_name TO new_table_name;

3. Is it possible to change the name of an SQL view itself?

No, it is not possible to change the name of an SQL view itself. Views are virtual tables that are defined by a query, and their names cannot be altered after creation. You would need to drop the existing view and create a new one with the desired name.

4. Can I change the name of a column in a view without affecting the underlying table?

Yes, changing the name of a column in a view does not affect the underlying table, as views are just virtual representations of the data from the table. You can change the column name in the view without altering the original table.

5. Will changing the name of a column in an SQL view affect any existing queries or reports?

Yes, changing the name of a column in an SQL view can potentially affect existing queries or reports that rely on that specific column name. It is important to update any affected queries or reports after making changes to the view to ensure they continue to function correctly.

Similar threads

Replies
51
Views
4K
Replies
5
Views
1K
Replies
18
Views
3K
Replies
7
Views
1K
Replies
1
Views
933
Replies
50
Views
5K
Replies
1
Views
1K
Replies
1
Views
934
Back
Top