Proper use of a Lookup table and adaptations for NET

Hello,
I need to create a few lookup tables and I often see the following:
create table Languages
Id int identity not null primary key (Id),
Code nvarchar (4) not null,
Description nvarchar (120) not null,
create table Posts
Id int identity not null primary key (Id),
LanguageId int not null,
Title nvarchar (400) not null,
insert into Languages (Id, Code, Description)
values (1, "en", "English");
This way I am localizing Posts with language id ...
IMHO, this is not the best scheme for Languages table because in a Lookup table the PK should be meaningful, right?
So instead I would use the following:
create table Languages
Code nvarchar (4) not null primary key (Code),
Description nvarchar (120) not null,
create table Posts
Id int identity not null primary key (Id),
LanguageCode nvarchar (4) not null,
Title nvarchar (400) not null,
insert into Languages (Code, Description)
values ("en", "English");
The NET applications usually use language code so this way I can get a Post in English without using a Join.
And with this approach I am also maintaining the database data integrity ...
This could be applied to Genders table with codes "M", "F", countries table, transaction types table (should I?), ...
However I think it is common to use int as PK in lookup tables because it is easier to map to ENUMS.
And know it is even possible to map to Flag Enums so have a Many to Many relationship in an ENUM.
That helps in NET code but in fact has limitations. A Languages table could never be mapped to a FLags Enum ...
... An flags enum can't have more than 64 items (Int64) because the keys must be a power of two.
A SOLUTION
I decided to find an approach that enforces database data integrity and still makes possible to use enums so I tried:
create table Languages
Code nvarchar (4) not null primary key (Code),
Key int not null,
Description nvarchar (120) not null,
create table Posts
Id int identity not null primary key (Id),
LanguageCode nvarchar (4) not null,
Title nvarchar (400) not null,
insert into Languages (Code, Key, Description)
values ("en", 1, "English");
With this approach I have a meaningfully Language code, I avoid joins and I can create an enum by parsing the Key:
public enum LanguageEnum {
[Code("en")
English = 1
I can even preserve the code in an attribute. Or I can switch the code and description ...
What about Flag enums? Well, I will have not Flag enums but I can have List<LanguageEnum> ...
And when using List<LanguageEnum> I do not have the limitation of 64 items ...
To me all this makes sense but would I apply it to a Roles table, or a ProductsCategory table?
In my opinion I would apply only to tables that will rarely change over time ... So:
    Languages, Countries, Genders, ... Any other example?
About the following I am not sure (They are intrinsic to the application):
   PaymentsTypes, UserRoles
And to these I wouldn't apply (They can be managed by a CMS):
   ProductsCategories, ProductsColors
What do you think about my approach for Lookup tables?
Thank You,
Miguel

>>IMHO, this is not the best scheme for Languages table because in a Lookup table the PK should be meaningful, right?<<
Not necessarily. The choice to use, or not to use, a surrogate key in a table is a preference, not a rule. There are pros and cons to either method, but I tend to agree with you. When the values are set as programming terms, I usually use a textual value
for the key. But this is nothing to get hung up over.
Bear in mind however, that this:
    create table Languages
      Id int identity not
null primary key
(Id),     
      Code nvarchar (4)
not null, Description nvarchar
(120) not
null,
is not equivalent to
    create table Languages
      Code nvarchar (4)
not null primary
key (Code),     
      Description nvarchar (120)
not null,
The first table needs a UNIQUE constraint on Code to make these solutions semantically the same. The first table could have the value 'Klingon' in it 20 times while the second only once.
>>However I think it is common to use int as PK in lookup tables because it is easier to map to ENUMS.<<
This was going to be my next point. For that case, I would only change the first table to not have an identity assigned key value, as it would be easier to manage at the same time and manner as the enum.
>>. A Languages table could never be mapped to a FLags Enum ...<<
You could, but I would highly suggest to avoid any values encoded in a bitwise pattern in SQL as much as possible. Rule #1 (First Normal Form) is partially to have 1 value per column. It is how the optimizer thinks, and how it works best.
My rule of thumb for lookup (or I prefer the term  "domain" tables, as really all tables are there to look up values :)), is all data should be self explanatory in the database, through data if at all possible. So if you have a color column,
and it contains the color "Vermillion", and all you will ever need is the name, and you feel like it is good enough to manage in the UI, then great. But bear in mind, the beauty of a table that is there for domain purposes, is that you can then store
the R, G, and B attributes of the vermillion color (254, 73, 2 respectively, based on
http://www.colorcombos.com/colors/FE4902) and you can then use that in coding. Alternate names for the color could be introduce, etc. And if UserRoles are 1, 2, 3, and 42 (I have seen worse), then
definitely add columns. I think you are basically on the right track.
Louis
Without good requirements, my advice is only guesses. Please don't hold it against me if my answer answers my interpretation of your questions.

Similar Messages

  • Lookup-table and query-database do not use global transaction

    Hi,
    following problem:
    DbAdapter inserts data into DB (i.e. an invoice).
    Process takes part in global transaction.
    After the insert there is a transformation which uses query-database and / or lookup-table.
    It seems these XPath / XSLT functions are NOT taking part in the transaction and so we can not access information from the current db transaction.
    I know workarounds like using DbAdapter for every query needed, etc. but this will cost a lot of time to change.
    Is there any way to share transaction in both DbAdapter insert AND lookup-table and query-database?
    Thanks, Best Regards,
    Martin

    One dba contacted me and made this statement:
    Import & export utilities are not independent from characterset. All
    user data in text related datatypes is exported using the character set
    of the source database. If the character sets of the source and target
    databases do not match a single conversion is performed.So far, that does not appear to be correct.
    nls_characterset = AL32UTF8
    nls_nchar_characterset = UTF8
    Running on Windows.
    EXP produces a backup in WE8MSWIN1252.
    I found that if I change the setting of the NLS_LANG registry setting for my oracle home, the exp utility exports to that character set.
    I changed the nls_lang
    from AMERICAN_AMERICA.WE8MSWIN1252
    to AMERICAN_AMERICA.UTF8
    Unfortunately , the export isn't working right, although it did change character sets.
    I get a warning on a possible character set conversion issue from AL32UTF8 to UTF8.
    Plus, I get an EXP_00056 Oracle error 932 encountered
    ORA-00932: inconsistent datatypes: expected BLOB, CLOB, get CHAR.
    EXP-00000: export terminated unsuccessfully.
    The schema I'm exporting with has exactly one procedure in it. Nothing else.
    I guess getting a new error message is progress. :)
    Still can't store multi-lingual characters in data tables.

  • Using a dynamic lookup table

    Hi,
    Simple question for the ODI guru's.. for an interface that we use, there is a requirement to dynamically look-up value's in a lookup table and then use these value's from the lookup table to write to a target table.
    This instead of hard coding string value's in the target table of the interface.
    ODI (11g) gives the option to use a lookup table, but it kind of assumes a relationship between the lookup table and source table - ie.it nicely allows you specify either an outer join or a subquery in the select statement.
    In this case, using the lookup, there is none however - no relationship between either lookup and source columns. So how would you do this?
    An outer join could be used, but then it requires to specify a join on columns of the source and lookup tables, so you could use dummy columns, but that is not ideal as columns might actually match. Any ideas?
    Cheers

    If there is no relationship between the values in your source table and those in the lookup table I can't see how you expect to perform a lookup - without a relationship it would be guesswork. For your requirements you would have to define a link table which held the associations between the 2 tables.

  • Need to create Enterprise field, LookUp Table and PDPs programmatically

    Hi,
    Please suggest how i can create Enterprise field, LookUp Table and PDPs, Workflow Stages, Phases programmatically for Project Server 2013. Any resource / blog link will be really be helpful.
    I searched google but most of them are for PS 2010
    Regards,
    Ankit G

    By Enterprise field i am assuming you mean Custom Field.
    The Google/Bing results for PS 2010 is referring to the PSI model. This model can still be used for Project Server 2013 OnPremise installations, but not for Project Online.
    The question is how do you want to create them/which technology do you want to use. you can program Agains the Project server through the PSI API, the CSOM API, the REST interface, Javascript and VBA code.
    I am gussing you want to create an application that uses C# therefore i will suggest to use the PSI or CSOM API.
    PSI is the old model, but is still supported in PS2013.
    The CSOM is the new model and only Works in PS2013 and comming versions.
    A great reference you should download is the Project Server 2013 SDK:
    http://www.microsoft.com/en-us/download/details.aspx?id=30435
    I am guessing you are new to Project Server programming so i will suggest you go with PSI as it has the most documentation.
    PSI:
    Getting started:
    http://msdn.microsoft.com/en-us/library/office/ff843379(v=office.14).aspx
    http://msdn.microsoft.com/en-us/library/office/ee767707(v=office.15).aspx
    Create Custom field:
    http://msdn.microsoft.com/en-us/library/office/websvccustomfields.customfielddataset.customfieldsdatatable.newcustomfieldsrow_di_pj14mref(v=office.15).aspx
    http://msdn.microsoft.com/en-us/library/office/gg217970.aspx
    Setting custom field values:
    http://blogs.msdn.com/b/brismith/archive/2007/12/06/setting-custom-field-values-using-the-psi.aspx
    http://msdn.microsoft.com/en-US/library/office/microsoft.office.project.server.library.customfield_di_pj14mref
    Lookuptables are the same procedure:
    http://msdn.microsoft.com/en-us/library/office/websvclookuptable_di_pj14mref(v=office.15).aspx
    Workflow phases/stages:
    http://msdn.microsoft.com/en-us/library/office/websvcworkflow_di_pj14mref(v=office.15).aspx
    PDP's:
    PDP's have to be created through the SharePoint interface as Web Part Pages. I havn't tried this.
    I think you want to do this in a backup/restore scenario. In this case you might consider the free tool Playbooks:
    http://technet.microsoft.com/en-us/library/gg128952(v=office.14).aspx

  • PowerPivot - Create a Lookup Table and Calculate Totals via PowerQuery

    Hi,
    I have got a question to powerpivot/powerquery.
    I have got one source file "product-sku.txt" with product data (product number, product size, product quantity etc.).
    In powerpivot I created via this text file 2 powerpivot tables:
    product-sku and
    products.
    The "products" table is a lookup table and was created via powerquery using the columns prodnumber, removing the prodsize and the prodquantity columns and then removing duplicates.
    My question: How could I show/leave a column prodquantity in the lookup table "products" which shows the total of all sizes per prodnumber?
    I need this prodquantity in the lookup table to do a banding analysis via the "products" table (e.g. products with quantity 0-100, 101-200 etc.). 
    I give you an example:
    source file columns (product-sku.txt):
    Source 
    Date
    ProdNumber
    ProdSize
    ProdQuantity
    ProdGroup
    ProdSubGroup
    ProdCostPrice
    ProdSellingPrice
    The powerpivot table "product-sku" contains all columns from the txt file above
    The lookup table "products" created via powerquery has the following columns:
    Source
    Date
    ProdNumber
    ProdQuantity (this column I would wish to add; if a prodnumber 123 had two sizes (36 and 38) with quantities of 5 and 10, the prodquantity should add up in the lookup table to 15. How could this be achieved?)
    I enclose a link to my dropbox with example files: PowerPivot-Example-Files
    Thank you for any help.
    Chiemo

    Chiemo,
    If you would like to consolidate to one table as Olaf has suggested, that would be very easy to do. I have included the modified DAX for the calculated column below. This calculated column would be created in the 'product-sku' table itself.
    You are correct in your assumption that you need an explicitly calculated column to most easily do banding analysis.
    Olaf is correct that avoiding the creation of a separate 'products' table as you have done is a good idea. I was not thinking about modeling best practices when I replied. If the only purpose of your 'products' table was to create this calculated column,
    then I do suggest deleting that table and implementing the calculated column in 'product-sku' with the DAX below.
    Edit: If you need to use 'products' as a dimension table which will have a relationship to a fact table, then it will be necessary to keep it. PowerPivot does not natively handle a many-to-many relationship. Dimension tables must have a unique key. If [ProdNumber]
    is the key, then it will be necessary to have your 'products' table. If you need to implement a many-to-many relationship, please see this
    post as a primer.
    =
    CALCULATE (
        SUM ( 'product-sku'[ProdQuantity] ),
        'product-sku'[ProdNumber] = EARLIER ( 'product-sku'[ProdNumber] )

  • I am trying to play a DVD on my MacBook Pro and transmit it to my TV (use my TV as the monitor) utilizing a VGA cable and adapter for the Mac but the only image that shows up on the TV is the MacBook wall paper, any ideas on how I can transmit to my TV?

    I am trying to play a DVD on my MacBook Pro and transmit it to my TV (using my TV as the monitor) utilizing a VGA cable and adapter for the Mac but the only image that shows up on the TV is the MacBook wall paper, any ideas on how I can transmit the movie from my MacBook to the TV?  I also tried an HDMI cable and had the same issue.

    you are probably seeing the extended display.. to see ur main display go to pefrences then display steeings and turn mirroring on.
    this will display ur mbp main screen. good luck.

  • Trying to use 2 different Dimension tables and make a hierarchy on some columns which are split into these dimensions .. how do I do that

    Trying to use 2 different Dimension tables and make a hierarchy on some columns which are split into these dimensions .. how do I do that

    If you need to make a hierarchy in an Attribute view you need to have all relevant fields/columns in the same Dimension table..

  • Can i use the lightning to usb camera adapter for sony cybershotdsc-w380

    DDoes anyone know how to use a lightning to sub camera adapter for a Sony cyber shot doc-w830

    This discussion may help.
    It mostly depends on the camera. Some cameras have a Transfer Mode, which does not attempt to charge while transferring pictures. does yours have such a setting?
    Alternatively you can try to plug a powered USB hub between the camera and the USB connector so the power is provided by the HUB rather than the iPad.
    Other than that, yes the Memory card reader may be a better option assuming your Camera uses Secure Digital (SD) type memory cards.

  • Identify reference Table and filed for...

    Hi
    How to identify the Reference table and field for the particular Currency and quantity field.
    Regards
    Raghav

    Hi there,
    if you want to find out the reference table and field for the particular currency or date field follow the steps given below.
    1. tcode SE11  and give the table name,
    2. double click on the dataelement for which you would like to findout the details.
    3. Place the cursor on the dataelement name and click on the Whereused button
       Utilities --> Where-Used list.
    4. Uncheck all the checkboxes and check Table Fields.
    5. Hit Enter, that should give you all the tables and fields where this dataelement is being used.
    6. You can mention any of the tables as a reference table or fields.
    Hope you found this useful.
    Thanks-
    Rahul.

  • Memory stic pro duo and adapter for cybershot dsc p200

    I boought a memory stick pro duo 2 gb and adapter for my cybershot  dsc p200 camera and when installed it reads no memory stick .

    Hi BigDawg,
    Welcome to the Sony Community!
    When you inserted the card in the camera, did you try to format it? Does this happen with other cards or just this one? And may I also ask the model of the adapter you're using?
    If you've tried to format the card and still get the same message, we recommend checking both the port and the card adapter for any dirt or debris. If this doesn't happen with other cards, the card or adapter that you're using may be defective.The dedicated adapter for this card is the MSAC-M2.
    If my post answers your question, please mark it as "Accept as Solution". Thanks_Mitch
     

  • Can I use the same icloud username and password for multiple phones?

    I have 6 iphones and wanted to use Apple Configurator to install the same apps on all 6 phones.  Some of the apps though, also require further installation by email.  Can I use the same iCloud username and password for all 6 phones to download the apps and also to configure email or do I need to create 6 different Apple IDs?

    If different people will be using these phones, you might be better off using the same Apple ID for the iTunes content...apps, music, etc. on each of these devices, but create different ID's for iCloud on each device. You can use one ID for the iTunes/App store, & a different ID for iCloud. That way, messages, notes, contacts, calendars, etc will be kept separate on each device.

  • HT2731 I have multiple phones on my account; do they all have to use the same Apple ID and Password for ITunes?

    I have multiple phones on my account; do they all have to use the same Apple ID and Password for ITunes?

    No.

  • Can I use icloud to synchronize contacts and calender for 1 ipad and 3 Windows 7/8 PC?

    Can I use icloud to synchronize contacts and calender for 1 ipad and 3 Windows 7/8 PC?
    regards,
    Jan

    Thanks! One more question ..... Will I have to enter appointments on an iCloud default calendar by logging in to my iCloud account every time, or can I just enter data on calendars in my 2 devices?

  • I was using my notes earlier today and now for some reason they are all gone. How does this happen and is there anything I can do to get them back, the new ones also that haven't been synced.

    I was using my notes earlier today and now for some reason they are all gone. How does this happen and is there anything I can do to get them back, the new ones also that haven't been synced.

    See Recover your iTunes library from your iPod or iOS device.
    tt2

  • Give me some PP important tables and Tcodes for abapers

    give me some PP important tables and Tcodes for abapers
    thank you,
    Regards,
    Jagrut Bharatkumar Shukla

    10     Production Planning (PP)
    10.1     Work center
         CRHH                    Work center hierarchy
         CRHS                    Hierarchy structure
    CRHD                    Work center header
    CRTX                    Text for the Work Center or Production Resource/Tool
         CRCO                    Assignment of Work Center to Cost Center
         KAKO                    Capacity Header Segment
         CRCA                    Work Center Capacity Allocation
         TC24                    Person responsible for the workcenter
         CRCO                    Allocation of costcentre to workcentre
                 S022                    Order Operation Data for Work Center
    10.2     Routings/operations
         MAPL                    Allocation of task lists to materials
         PLAS                    Task list - selection of operations/activities
         PLFH                    Task list - production resources/tools
         PLFL                    Task list - sequences
         PLKO                    Task list - header
         PLKZ                    Task list: main header
         PLPH                    Phases / suboperations
         PLPO                    Task list operation / activity
         PLPR                    Log collector for tasklists
         PLMZ                    Allocation of BOM - items to operations
    10.3     Bill of material
         STKO                    BOM - header
         STPO                    BOM - item
         STAS                    BOMs - Item Selection
         STPN                    BOMs - follow-up control
         STPU                    BOM - sub-item
         STZU                    Permanent BOM data
         PLMZ                    Allocation of BOM - items to operations
         MAST                    Material to BOM link
         KDST                    Sales order to BOM link
    10.4     Production orders
         AUFK                    Production order headers
         AFIH                    Maintenance order header
         AUFM                    Goods movement for prod. order
         AFKO                    Order header data PP orders
         AFPO                    Order item
         RESB                    Order componenten     
           AFVC                    Order operations
         AFVV                    Quantities/dates/values in the operation
         AFVU                    User fields of the operation
         AFFL                    Work order sequence
         AFFH                    PRT assignment data for the work order(routing)
         JSTO                    Status profile
    JEST                    Object status
         AFRU                    Order completion confirmations
               PRT’s voor production orders
         AFFH                    PRT assignment data for the work order
         CRVD_A               Link of PRT to Document
         DRAW                    Document Info Record
         TDWA                    Document Types
         TDWD                    Data Carrier/Network Nodes
         TDWE                    Data Carrier Type
    10.5     Planned orders
         PLAF                    Planned orders
    10.6     KANBAN
         PKPS                    Kanban identification, control cycle
         PKHD                    Kanban control cycle (header data)
         PKER                    Error log for Kanban containers
    10.7     Reservations
         RESB                    Material reservations
         RKPF                    header
    10.8     Capacity planning
    KBKO                    Header record for capacity requirements
    KBED                    Capacity requirements records
    KBEZ                    Add. data for table KBED (for indiv. capacities/splits)
    10.9     Planned independent requirements
         PBIM                    Independent requirements for material
         PBED                    Independent requirement data
         PBHI                    Independent requirement history
         PBIV                    Independent requirement index
         PBIC                    Independent requirement index for customer req.

Maybe you are looking for