MS Access -- how to get other fields using a primary key - ms-access

I'm adding a couple fields to a form made by someone else and am having trouble getting the value in one of the fields.
The field displays a location and is called "location." But when I set a new field to =[location], it returns the primary key from the data table of locations instead of the location. When I try to get the value directly from the source, [Table]![originalLocation] returns #name?.
How can I get a field associated with a primary key? So far everything returns the value of the primary key. Thanks.

Related

Creating Surrogate Keys in Access

I have a project that I am working on where we have to create a registration system for a university in Access. One of the tables requires a surrogate key for one of the fields, and I am not sure how I can create a surrogate key.
The column instructions look like this:
Field Name Data Type Field Size Caption Format Req'd Index Unique Key Ref. Table Other
FacultyID Text 4 blank blank Yes Yes Primary blank Input Mask '0000;1;_'
FirstName Text 32 blank blank Yes No Surrogate* blank blank
So the first field, FacultyID is straightforward and simple to make. But the FirstName field requires a surrogate key that I do not know how to make.
It also has the asterisk next to it, and at the bottom of the page the asterisk reads:
*Index [LastName], [FirstName]: Duplicates Allowed (surrogate key)
The LastName field is listed later but I didn't show it in my question. What confuses me with this, however, is that in the column instructions, it says that the Index field should be No for FirstName, but this note at the bottom of the page makes it seem like it should be Yes (Duplicates OK) and I do not know what to put.
So can anyone help me figure out how to make the FirstName a Surrogate Key, and also what I should be putting in the Index field?
You'd need to post more info (like, is there an employees table?), but it looks like the instructions want you to use an employee's last and first name's as a composite key vs. surrogate. When designing a table, you can hold SHIFT + the fields you want to include in your key:
Then press the Primary Key button in the Tools section at the top:
And you'll end up with a composite primary key:
I think the wording on your requirements sheet is a little wonky. I think the only way to get a LastName, FirstName column is via some sort of Data Macro or through an append query.
Also, even if you don't use it for anything, I would suggest ALWAYS having an AutoNumber ID field. I've had database integrity issues when not having a key on each table.
But, without seeing the full assignment sheet, I would be tough to dial-in what you needed specifically.

Issues with Slowly Changing Dimension Table with Primary Key

I have a package designed by another developer who used to work for the company. The package takes data from the source and inserts it into the destination. The slowly changing dimension task has 4 columns, set as historic attributes. Meaning it will insert a new row when any of the value changes. The business key is called PropertyID.
In destionation table, PropertyID is the primary key. When the package runs, we get primary key violation error. Which is understandable, because the destination table cannot insert a duplicate value when there is a change in the historic attribute. It is may be not the best design.
I want to correct this but i am not sure of the right approcah. I tried to add a new INT IDENTITY column (to use as a business key in SCD wizard) to the destination table and make the current PropertyID column as not primary key. But the INT IDENTITY column does not show up in the SCD wizard.
If someone can show me right approach to it, I would be much grateful.
Thanks.
In a slowly changing dimension, the destination table will have two types of keys, the surrogate key which will tie out to the fact table, and the business key, which identifies the record from the source.
You do not want the business key as the primary key on the destination in a slowly changing dimension. That is the point of the SCD, you will have multiple rows per business key since you are tracking changes. If you are not wanting to do this, and your table is all type one changes (overwrites with current value), then the SCD transform is not what you want.
See this link ... https://en.wikipedia.org/wiki/Surrogate_key
It looks like your are trying to design a Type 2 SCD as the changed records are getting inserted. In this case there should be a date field to track when a particular record was changed as well as to identify the current record. The primary key in the destination table should also be in property_id and a date field. You can refer the below link to check how is type 2 SCD Designed.
http://datawarehouse4u.info/SCD-Slowly-Changing-Dimensions.html

Not create a Primary Key when typing in a form

I was wondering if there is a way for a form to not generate a Primary Key as soon as I start typing on a field (this is just in case I don't really want to insert)? Can it show what Primary Key will be generated when I do/only generate and insert in the table?
There is a difference between a Primary Key and a automatically generated number. It is true that Access proposes an autonumber field as a PK, but you can definitely switch it to a number or character field. Then, you will have to find a way to enter manually the PK value, or generate it through code(*), before inserting the record in the table.
(*) In case you are using numbers as PKs, the logic could be here to check the higher PK value already in the table (max()) and add 1 to it.

Unique on Compound Columns

I am trying to ensure that the values in RESTAURANTID and TABLENUMBER, together, are Unique using PowerDesigner (12.5). I've tried creating an alternate key which resulted in the following in my .sql file:
create table TABLES
(
TABLEID int not null,
RESTAURANTID int not null,
TABLENUMBER int not null,
primary key (TABLESID),
key AK_mykey (RESTAURANTID, TABLENUMBER)
);
However with this, I can still enter identical values for RESTAURANTID and TABLENUMBER more than once.
I used this http://www.tek-tips.com/viewthread.cfm?qid=403554 to create the alternate key in PowerDesigner.
Would anyone know the proper way to achieve this in PowerDesigner?
Note: This isn't a duplicate of the question posted above as I'm looking for a way to achieve this in PowerDesigner without having to edit the generated sql file afterwards.
The unique property for keys (other than primary) in MySQL is stored as an extended attribute on the key.
You can modify it by displaying, and going to the MySQL tab in the Key properties dialog.
Or, in Model>Keys, you can use the Customize Columns and Filter button to show the Ext Unique (extended) property in the list of keys, so that you can set this unique property on several keys at once.
Or, you can create your own copy of the MySQL DBMS, and edit it. Under Profile>Key (using the right-click), add an event handler Initialize with the following Event Handler Script, so that each new key has ExtUnique set:
Function %Initialize%(obj)
obj.setextendedattribute "ExtUnique",true
%Initialize% = True
End Function
You are just adding a normal index. What you need is a unique index. Just replace key AK_mykey (RESTAURANTID, TABLENUMBER) with unique key AK_mykey (RESTAURANTID, TABLENUMBER) in your query and you are done.
In Power Designer:
Open the "TABLES" table properties (right click -> properties)
Keys tab
Insert row (name it to "AK_mykey")
Apply (previously inserted row saved)
On the "AK_mykey" row: right click -> properties
Columns tab
Add columns button
Select the required columns (RESTAURANTID, TABLENUMBER)
OK, OK, OK buttons
+1 You can check the result in table properties preview tab.
alter table TABLES
add unique AK_mykey (RESTAURANTID, TABLENUMBER);

Creating a custom Serial Number in Primary Key in mvc4

I am building a website in mvc4 and i want to ask that as i am registering a new user than the user-profile table automatically updated with user-id as auto increment in the 1,2,3,4,5,...sequence but i want this primary key to auto-increment in some other way such as psk1,psk2,psk3...................can i have this ?? if Yes how it is possible?
I have try using custom membership provider but i am not successful by using that method so can any one have better option other than this?
I can think of three ways of creating unique primary keys
Autoincrement by identity.
This is the method that you are already familiar with, leading to automatic generation of primary keys of type 1,2,3,....
Using UUID.
This is a global unique identified which you can create in .NET and pass it as value in your database record.
Custom creation of primary key
If there is a special need, you could set your data table column to be primary Key of type varchar and create either in the .NET domain, or in the SQL server using a trigger. There, you could find the last inserted ID, parse it, increment the integer part and form the new unique primary key. .
Hope I helped!