Create a (MS)SQL View

Discussion in 'Databases' started by ChaosTrivia, Sep 17, 2010.

  1. #1
    Hello !
    I have two tables:

    CREATE TABLE [dbo].[Entries](
    	[ID] [int] IDENTITY(1,1) NOT NULL,
    	[Value] [nvarchar](256) NOT NULL
    )
    Code (markup):
    And a table that connects between entries, creating pairs of entries:

    CREATE TABLE [dbo].[Connections](
    	[ID] [int] IDENTITY(1,1) NOT NULL,
    	[Entry1ID] [int] NOT NULL,
    	[Entry1ID] [int] NOT NULL
    )
    Code (markup):
    How can I display all connections in a view, where instead of numbers I show their corresponding text values? What t-SQL command will do the job?

    Thanks in advance!
     
    ChaosTrivia, Sep 17, 2010 IP
  2. merabasera

    merabasera Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    hi,
    You simply create view from joining both these tables on the ID coloumn
     
    merabasera, Oct 8, 2010 IP
  3. RonBrown

    RonBrown Well-Known Member

    Messages:
    934
    Likes Received:
    55
    Best Answers:
    4
    Trophy Points:
    105
    #3
    MS SQL has a graphical interface where you can create views for any number of linked tables. While it's great being able to produce the code yourself, time is always a factor and using this interface is quicker and easier.

    The best thing to do is create a database diagram with all the linked tables and types relationships first, and when you come to create the views it will retain these relationships when you insert the relevant tables into the view.
     
    RonBrown, Oct 10, 2010 IP