Realizing Three States By Storing Values in Single Column In DB Table - database

I Have List of Products Displayed in Web Page.
Each product is identified by unique product id in database.
Initially when the page loads its would be shown as Both tick and Cross under every product (Image 1)
Once the User click Tick Symbol for particular product I will display it as Interested (Image2)
When the User click Cross Symbol for particular product I will display it as Not Interested (Image3)
I should load the user last selected preference every time the page loads by storing the user name and productId for which the user is Interested.
This remains simple when there are only two states where the user might either be interested or not interested since i will store all the interested ProductaIds in DB and Use them to load user preference.That is I will apply class Interested for all the ProductIds which are in DB and NotInterested class for all those Ids which are not In database.
Now the third state is the one for which the user never touched - Image1.
I already have a DB Table Like Below
CREATE TABLE UserPreference(
UserId INT,
Interested_ProductsId VARCHAR(150)
);
I am Storing the Interested_ProductsId as CSV Product Ids (i.e) 5,75,2,15 are all product Ids
Now my question is it possible to realize the third state(Image1) in the CSV.I am storing only ProductsIds in which customer interested.How to realize the ProductsId in which customer is Not interested(Image3) and customer never clicked(Image1).
Thanks in Advance

Yes this is possible: Introduce a new column:
Type tinyint not null
CHECK (Type in (1, 2, 3))
And define type as one of your three states.
You can associate arbitrary data with your join table items. You basically promote them to "entities" that way.

Related

How do I create a new record in a table according to primary key of another tab in an Access Form?

I have two tables. The first one is the list of my customers with their auto-generated ID, their name and their status in my DB. The second table is the list of my customers' phone numbers and whether it is a mobile or landline. One customer can have many phone numbers, that is why I keep in every record in table2 the CustomerID.
I want to create a form that allows me to add a new customer to my list, and in a separate form, add one or more phone numbers ACCORDING to the CustomerID I've just add. In the future I will have many more tables like Customer_Phones_List also linked to Customers_List so I'm not sure if a subform is the best option.
How do I do that in MS Access ?
Build form/subform(s) arrangement. Can use a tab control for multiple subforms to conserve screen space. Each page of tab control can have a subform that is linked to data on main form.

Filtering a result by the content of another table

I'm supposed to do a stakked column chart visualization about the total number of permits granted by authorizing department. So far ok, the problem is my datamodel.
My datamodel consists in 3 main tables:
PDT's(work permits)
Departamentos (SubDepartments)
Referencia(Departments)
I leave here the type of relationship between them:
The 1st table below It's about subdepartments. The primary key is the ID Column which is directly related to Nombre Column because It refers to Departments name. The thing is that Each of departments are inside another bigger than 1st one E.G.: Petronor is the biggest department, thats why It is not inside another one and the column name of DepartamentoPadreId is null in this field, but Economico Financiera, Fiabilidad y Mantenimiento, Ingeniería y Desarrollo, Producción, P&O, SMA and OTROS are inside of PETRONOR and this is how works this table.
The problem is that names are too long to put in my Dashboard so what I did was create a new table relating the names from DepartmentoPadreId to another with the acronyms.
Now I have my last table where I have the work permits of employees. This permits are made by a Department for another. This means that I have several relations with this table by Departamentos Table. One relation is with the Authorizing Department and another with Authorized Department. And here is my problem
What I expect to get is two stakked column charts with different values for each one. One: the Total number of permits by Authorized Department Second: The total number of permits by Authorizing Department.
The problem is I'm getting the name from the Relacion-Direccion Table because is the only table that contains the name I want to appears in my dashboard and I dont know how to filter It by the specific column in PDTs table I want.

Databases - Do tables in a database have to contain all global instances or can they be specific to a certain ID

I'm trying to model a database for facebook users. For my User table I have {account_name, account_id, ..., password} as variables. I'm trying to create a table for friends of that user, such as a Friendlist or Contacts table, but I'm wondering would the contacts table have to have a list of all the possible friendships (i.e. {user_id, friend_id, friends_since,...} ) or is it possible to have the contact table specific to a certain user_id (so {contact_id, friends_since, no_of_mutual_contacts, etc..}).
This is probably just the object orientated part of my brain coming into action, but say for example if we were using a Cinema database. There were 5 cinemas and each had 5 screens, CINEMA is a table and SCREEN is a table. Would the SCREEN table have 25 instances of data or is there some way that the SCREEN table would only contain the 5 screens corresponding to a specific CINEMA.
This comes back to my original question, would the Contacts table have to be a global table containing all friendships, or does the Contacts table only return the contacts specific to the user_id.
For some reason when I'm looking at the relational chart of the database I see the connections ressembling a somewhat object like structure where the links are just denoted members like user.Contacts or user.Events.
Normally a table in a relational database will record all facts of a given type, e.g. user <user_id> is friends with user <friend_id> since <friends_since>.
You can create views for given users if required, or just specify a user_id in your queries, to get the subset of rows applicable to a specific user.
Creating a physical table specific to certain users would create difficulties if you wanted to get all the rows for a certain friend_id.

Bound combo box in form does not always update table

I'm struggling with a problem which I can't work out is due to a logical error, a design error or both. Or maybe it's something else entirely.
I have created a simple customer services database and form based user-interface for my company. When a user answers the phone they are supposed to log the call in the system if it is an issue relating to a product.
Sometimes a chain of stores which we have a special relationship with calls up on behalf of customers and we take their reference number and give them ours. This system actually works pretty well if I may say so myself (!), but I noticed after a while that when this store calls up and gives us their number, when they are logged into the system their branch number/name is not updated in the table record.
Here is a summarised outline of the relevant database tables. I renamed the store to SpecialStore:
Issues
IssueReference
ProductID
CustomerID
SpecialStoreBranch
Customers
...
Products
...
SpecialStore
SS_ID
City
Address
The idea is that even if it is either a customer or the store with their own IDs, the products are still stored in the same Products table, just with either the CustomerID or SS_ID filled in. Then when issues are logged, the store or customer is set and logged against a product.
In my main form I have a variety of boxes for a new issue to be filled in. There are combo boxes to select the CustomerID, ProductID etc, and of course the SpecialStoreBranch. These are all bound to the table, and the combo boxes all have row sources relating to their particular table. E.g. CustomerID combo box is a list of the IDs in the Customers table. (This is filtered to the required one elsewhere in the form.)
The Issues table SpecialStoreBranch field has the following query as its Row Source:
SELECT SpecialStore.[SS_ID], [SpecialStore].[City] FROM SpecialStore;
This is the same row source for the combo box on my main form.
The Column Count is 2, with the Bound Column as 0 and the column widths, if necessary, are 1cm;2.544cm.
My main form combo box SpecialStoreBranch has the other attributes:
Limit to List = yes
Allow Value List Edits = no
Inherit Value List = yes
Show Only Row Source Values = no
On the form the CustomerID and ProductID store correctly when the record is saved, and they are also from combo boxes. The form refreshes to update those fields when another part of the form (adding new customers and products) is changed. Could this be why the SpecialStoreBranch does not update? What am I missing? Is there a way to test this? I have been trying to run user tests to see if it ever works, but all I know is that it doesn't always set. If I have forgotten a piece of information let me know.
Edit:
Looking here: BoundColumn-Propery, I'm not sure if setting the bound column to 0 is doing what I think it's doing. But even then it should still use that id number to input into the table I would have thought and if they are all the same, what does it matter. When I tried setting it to 1, it took the text value in the table. Confusing!

How to populate a text item from Oracle table using Oracle forms (Middleware) 11gR2

I am using Oracle with Oracle Forms builder (Middleware) both 11gR2. I am creating a system for purchasing records. I have the following 2 tables.
(a) product (master) : prodid(PK), prodname ...... etc.
(b) purchase (detail) : prodid(FK), quantity, ...... etc.
My plan: All the product details will be in the product table. purchase table will be used only to input purchase information. This table can't input any new product. If any new name, that info will have to be input into product table first. This way I can reduce duplicate names.
Now I am having difficulties relating to prodname (name of the product) column in the form.
I created forms using the purchase table only. This table does not have the prodname (because I put this field in product table) column. But during data entry, they need to see the product name !
So I created text item (tabular, database - no). Then I created LOV, attached to text item, input the prodid in prodid field in the form. LOV part is fine.
I run the form. click the text item, LOV appears, select a name, click OK. product name, product id, etc. appears in their fields as it should be. LOV is working fine. Now I can only input data but having difficulties updating. I mean if I input a name (LOV) in the text item, press execute query, shows records from the database but names in the text item disappear. Since the name is not here, it's not comfortable to update.
I think LOV is not the good idea here. May be I need to use PL/SQL in a trigger somewhere.
But I could not figure it out. I searched google but no luck. Is there anyone who can give me any idea or some example code/trigger please.
Since the product name is an non-database item, when execute query runs, the field is cleared and since no column is assigned to that field, it doesn't repopulate.
The usual way to populate this field is to have a function which returns the product name based on the id that is pressed and call the funtion in POST-QUERY trigger.
Basically it's a pretty simple task but I was having difficulties due to the lack of my experience. However, what I have done is -
create the text item (name : product_name) in the canvas
set properties for the product_name (database : No, .... etc as needed).
Create a block level POST-QUERY trigger and write the PL/SQL block to populate the field. For example, I wrote the following.
BEGIN
SELECT prodname INTO :purchase.product_name
FROM product WHERE product.prodid = :purchase.prodid ;
END ;
That's it and when perform execute_query in the form, it will bring the product name from another table. - Query problem is solved.
Now create an LOV using product table to bring the product name and product id.
Associate this LOV to the product_name text item. So whenever you need to input information about a purchase, just use the LOV to populate the product name field. And then input the subsequent fields as well.
This way both of my issues (query and data entry) are resolved.
I did this according to the suggestions given by Sathya and a video (6 minutes) from the youtube at https://www.youtube.com/watch?v=0nqldnGt8KA.
Thanks to Sathya and youtube.

Resources