Rename column when creating a view : Create View « View « SQL Server / T-SQL

SQL Server / T-SQL
1. Aggregate Functions
2. Analytical Functions
3. Constraints
4. Cursor
5. Data Set
6. Data Type
7. Database
8. Date Timezone
9. Index
10. Insert Delete Update
11. Math Functions
12. Select Query
13. Sequence
14. Store Procedure Function
15. String Functions
16. Subquery
17. System
18. Table
19. Table Joins
20. Transact SQL
21. Transaction
22. Trigger
23. View
24. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
SQL Server / T-SQL » View » Create View 
Rename column when creating a view


1create table employee(
2>     ID          int,
3>     name        nvarchar (10),
4>     salary      int )
5> GO
1>
2create table job(
3>     ID              int,
4>     title nvarchar  (10),
5>     averageSalary   int)
6> GO
1>
2>
3insert into employee (ID, name, salaryvalues (1,  'Jason', 1234)
4> GO

(rows affected)
1insert into employee (ID, name, salaryvalues (2,  'Robert', 4321)
2> GO

(rows affected)
1insert into employee (ID, name, salaryvalues (3,  'Celia', 5432)
2> GO

(rows affected)
1insert into employee (ID, name, salaryvalues (4,  'Linda', 3456)
2> GO

(rows affected)
1insert into employee (ID, name, salaryvalues (5,  'David', 7654)
2> GO

(rows affected)
1insert into employee (ID, name, salaryvalues (6,  'James', 4567)
2> GO

(rows affected)
1insert into employee (ID, name, salaryvalues (7,  'Alison', 8744)
2> GO

(rows affected)
1insert into employee (ID, name, salaryvalues (8,  'Chris', 9875)
2> GO

(rows affected)
1insert into employee (ID, name, salaryvalues (9,  'Mary', 2345)
2> GO

(rows affected)
1>
2insert into job(ID, title, averageSalaryvalues(1,'Developer',3000)
3> GO

(rows affected)
1insert into job(ID, title, averageSalaryvalues(2,'Tester', 4000)
2> GO

(rows affected)
1insert into job(ID, title, averageSalaryvalues(3,'Designer', 5000)
2> GO

(rows affected)
1insert into job(ID, title, averageSalaryvalues(4,'Programmer', 6000)
2> GO

(rows affected)
1>
2>
3>
4select from employee;
5> GO
ID          name       salary
----------- ---------- -----------
          Jason             1234
          Robert            4321
          Celia             5432
          Linda             3456
          David             7654
          James             4567
          Alison            8744
          Chris             9875
          Mary              2345

(rows affected)
1select from job;
2> GO
ID          title      averageSalary
----------- ---------- -------------
          Developer           3000
          Tester              4000
          Designer            5000
          Programmer          6000

(rows affected)
1>
2SELECT e.ID 'EmployeeID',e.name 'EmployeeName', j.title 'EmployeeTitle'
3FROM Employee e INNER JOIN job j
4>         ON e.ID = j.ID
5> GO
EmployeeID  EmployeeName EmployeeTitle
----------- ------------ -------------
          Jason        Developer
          Robert       Tester
          Celia        Designer
          Linda        Programmer

(rows affected)
1>
2>
3CREATE VIEW ViewOnEmployee
4> AS
5SELECT e.ID 'EmployeeID',e.name 'EmployeeName', j.title 'EmployeeTitle'
6FROM Employee e INNER JOIN job j
7>         ON e.ID = j.ID
8> GO
1>
2select from ViewOnEmployee
3> GO
EmployeeID  EmployeeName EmployeeTitle
----------- ------------ -------------
          Jason        Developer
          Robert       Tester
          Celia        Designer
          Linda        Programmer

(rows affected)
1>
2> drop table employee;
3> drop table job;
4> GO
1>
           
       
Related examples in the same category
1. More Complex Views: inner join
2. Create a simple view and retrieve data from it
3. Simple Views
4. Use view to filter out the NULL data
5. When you create a view, you're really just naming a SQL SELECT statement
6. Stored Procedures as Parameterized Views
7. CREATE VIEW statement called SCHEMA BINDING tells SQL Server to check for dependencies and disallow any modifications that would violate them
8. CREATE VIEW myView WITH SCHEMABINDING
9. WITH CHECK OPTION keeps the results synchronized with the table(s)
10. View cannot be sorted with ORDER BY unless the TOP command is also used
11. Column names in a view can be defined in the CREATE statement
12. Create view based on table-join query
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.