Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 How to create a view of table with few columns

Author  Topic 

palaparu
Starting Member

20 Posts

Posted - 2010-10-27 : 12:23:43
How to create a view of table with few columns,

taking only 5 coulmns out of 10 columns

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-27 : 12:27:44
CREATE VIEW viewname_here
AS
SELECT
column1,
column3,
column5,
column7,
column9
FROM YourTable


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

palaparu
Starting Member

20 Posts

Posted - 2010-10-27 : 13:39:15
thanx dude..
Go to Top of Page

palaparu
Starting Member

20 Posts

Posted - 2010-10-27 : 13:40:09
but how to create a view of few columns in a table... which is present in the other database
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-27 : 14:20:11
quote:
Originally posted by palaparu

but how to create a view of few columns in a table... which is present in the other database


same as what webfred showed with small addition as below


CREATE VIEW viewname_here
AS
SELECT
column1,
column3,
column5,
column7,
column9
FROM DBName.SchemaName.YourTable


provided dbs are in same server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

palaparu
Starting Member

20 Posts

Posted - 2010-10-27 : 14:32:48
Hi visakh, I appreciate ur answer.....

But i need to create a view with 5 columns in one table and 5 columns from other table
totally the create view must have 10 columns
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-27 : 14:36:25
show the structure of two tables and then eplain which all columns you want in the view

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

palaparu
Starting Member

20 Posts

Posted - 2010-10-27 : 14:50:53
there are two tables 1. Hyderabad 2. Atlanta

1. Hyderabad has columns like a,b,c,d
2. Atlanta has columns like e,f,g,h

Now i want to create a view with columns b,c,f,g


Go to Top of Page

palaparu
Starting Member

20 Posts

Posted - 2010-10-27 : 14:53:24
CREATE VIEW vizag AS SELECT b,c from Hyderabad then

how to add f,g columns from ATLANTA Table in that query to get b,c,f,g in one view
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-27 : 14:56:29
then you need to have some columns by which you can relate between two tables. how are they related?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

palaparu
Starting Member

20 Posts

Posted - 2010-10-27 : 14:58:22
how r they related ante ela chepali boss....
Go to Top of Page

palaparu
Starting Member

20 Posts

Posted - 2010-10-27 : 15:06:56
number ivvandi okasari call chesta
Go to Top of Page
   

- Advertisement -