Database Simplified Headline Animator

Database Simplified

Monday 30 May 2011

View Doesn’t Not Add Column Automatically When * Is Specified in The View. See How

 

--Create A New Table
Create Table DemoTable
(Id Int,Name Varchar(40),Gender Char(1))

Go

--Insert Some Data
Insert Into DemoTable
Values (1,'Kuldeep','M'),(2,'Praveen','M'),(3,'Radhika','F')

Go

 

Select * from DemoTable

Go

image

--Create View With Select *

Create View vw_DemoTable
As
Select * From DemoTable
Go

 

Select * from vw_DemoTable

image

 

--Add New column Age to DemoTable
Alter Table DemoTable Add Age Int

go

Select Data From Both table and View and see the Difference. View Doesn’t Table Newly added column bydefault.

Select * from DemoTable – Table

Select * from vw_DemoTable -- View

Go

image

It Required View to Be Altered.

ALTER View [dbo].[vw_DemoTable]
As
Select * From DemoTable

GO

 

Select Data Again

Select * from DemoTable  --Table

Select * from vw_DemoTable   --View

image

Sunday 29 May 2011

How to Copy Comma Seprated Columns Of A Table (UnDocumented)




As we can see there is no option to copy column names but there is a undocumented option to do so see the following image.