dcsimg
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2014
    Posts
    5

    SQL query help foreign key

    Hi,

    I have tried to look for help on this on the net but can't find any.
    I got a table that looks like this

    tableA.uid_code tableA.str_code tableA.str.name tableA.uid_r_code (this links to uid.code)
    1 A Apple 2
    2 B Banana 1
    3 C Cat 1

    How do I do a SELECT query to get all the columns above but for tableA.uid_r_code instead of showing 2,1 and 1, show the str_name that is linked to it, so show Banana, Apple and Apply?

    Thanks

  2. #2
    Join Date
    Nov 2014
    Posts
    5
    sorry the top didn't appear correctly

    Code:
    tableA.uid_code tableA.str_code tableA.str.name tableA.uid_r_code (this links to uid code)
    1               A               Apple           2
    2               B               Banana          1
    3               C               Cat             1
    Last edited by SpywareDr; 11-27-2014 at 09:09 AM.

  3. #3
    Join Date
    Sep 2002
    Posts
    5,938
    Is tableA a table name? All columns are in same table? Which rdbs do you use?

  4. #4
    Join Date
    Nov 2014
    Posts
    5
    Quote Originally Posted by rmiao View Post
    Is tableA a table name? All columns are in same table? Which rdbs do you use?
    yes, tableA is a table

    All columns with are within the same table

    SQL DB?

  5. #5
    Join Date
    Sep 2002
    Posts
    5,938
    Why need fkey that references the column in same table?

  6. #6
    Join Date
    Sep 2002
    Posts
    5,938
    For sql server db, you can't have '.' in column name without [ ] surrounded.

  7. #7
    Join Date
    Nov 2014
    Posts
    5
    Quote Originally Posted by rmiao View Post
    Why need fkey that references the column in same table?
    I'm not sure, i didn't create the database

  8. #8
    Join Date
    Nov 2014
    Posts
    5
    Quote Originally Posted by rmiao View Post
    For sql server db, you can't have '.' in column name without [ ] surrounded.
    opps...yeah I supposed to type in TableA.str_name instead of a '.' in the middle

  9. #9
    Join Date
    Feb 2014
    Location
    Riviera Beach, Maryland, USA
    Posts
    51
    Microsoft Developer Network > Characters that are not allowed in table name & column name in sql server ?
    The Common rules:
    Rules for Regular Identifiers

    The rules for the format of regular identifiers depend on the database compatibility level. This level can be set by using ALTER DATABASE. When the compatibility level is 100, the following rules apply:

    1. The first character must be one of the following:

      • A letter as defined by the Unicode Standard 3.2. The Unicode definition of letters includes Latin characters from a through z, from A through Z, and also letter characters from other languages.

      • The underscore (_), at sign (@), or number sign (#).

        Certain symbols at the beginning of an identifier have special meaning in SQL Server. A regular identifier that starts with the at sign always denotes a local variable or parameter and cannot be used as the name of any other type of object. An identifier that starts with a number sign denotes a temporary table or procedure. An identifier that starts with double number signs (##) denotes a global temporary object. Although the number sign or double number sign characters can be used to begin the names of other types of objects, we do not recommend this practice.

        Some Transact-SQL functions have names that start with double at signs (@@). To avoid confusion with these functions, you should not use names that start with @@.

    2. Subsequent characters can include the following:

      • Letters as defined in the Unicode Standard 3.2.

      • Decimal numbers from either Basic Latin or other national scripts.

      • The at sign (@), dollar sign ($), number sign (#), or underscore (_).

    3. The identifier must not be a Transact-SQL reserved word. SQL Server reserves both the uppercase and lowercase versions of reserved words.

    4. Embedded spaces or special characters are not allowed.

    5. Supplementary characters are not allowed.
    When identifiers are used in Transact-SQL statements, the identifiers that do not comply with these rules must be delimited by double quotation marks or brackets.

    Hope this help you Sahil

    thanks....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.