Restructure Database using Oracle (SQL-Developer) - oracle11g

this might be a simple question, but I'll ask anyway :)
Lets say I got a table in a database (oracle) which is currently stored in the first normal form.
Now I would like to convert this table into the third normal form. But I don't exactly know how. OK, I know how to put the table into third NF on paper, no problem but how do I do it technically?
I'll just give an example:
My tabe has the following attributes:
InvoiceNr. | Date | StaffNr. | Name | Lastname | Street | Zip | City
Now I would like to put it in the following format:
Table Invoice:
InvoiceNr. (PK) | Date | StaffNr.
Table Staff:
StaffNr. (PK) | Name | Lastname | Street | Zip
Table Zip:
Zip (PK) | City
Thank you very much in advance ;)
Thomas

Related

How to search for unique users in this dynamodb table?

How does one return a list of unique users from a dynamodb table with the following (simplified) schema? Does it require a GSI? This is for an app with small number of users, and I can think of ways that will work for my needs without creating a GSI (like scanning and filtering on SK, or creating a new item with list of user ids inside). But what is the scalable solution?
------------------------------------------------------
| pk | sk | amount | balance
------------------------------------------------------
| "user1" | "2021-01-01T12:00:00Z" | 7 |
| "user1" | "2021-01-03T12:00:00Z" | 5 |
| "user2" | "2021-01-01T12:00:00Z" | 3 |
| "user2" | "2021-01-03T12:00:00Z" | 2 |
| "user1" | "user1" | | 12
| "user2" | "user2" | | 5
Your data model isn't designed to fetch all unique users efficiently.
You certainly could use a scan operation and filter with your current data model, but that is inefficient.
If you want to fetch all users in a single query, you'll need to get all user information into a single partition. As you've identified, you could do this with a GSI. You could also re-organize your data model to accommodate this access pattern.
For example, you mentioned that the application has a small number of users. If the number of users is small enough, you could create a partition that stores a list of all users (e.g. PK=USERS). If you could do this under 400kb, that may be a viable solution.
The idiomatic solution is to create a global secondary index.

Put key on wrong record

I have a problem connecting app maker with Google Cloud Platform. First I created two tables with one(department) to many(employee) relation. I also created an employee form.
Datasource on panel using employee, and on form using inherited:employee(create). Submit button using SaveChanges To Datasource. My Problem is, when I create the first record, it only saves employee data, while department_fk is empty.
When I create the second record, it will create data, but the department_fk will be placed on the first record.
+------+--------+---------------+-----------------------+-----------+
| id | name | department_fk | email | phone |
+------+--------+---------------+-----------------------+-----------+
| 150 | john | 262 | bermuara#gmail.com | 3393939 |
| 151 | brian | NULL | takdungder#gmail.com | 03030303 |
+------+--------+---------------+-----------------------+-----------+
On the above record, brian should be in department_fk 262, but it assigns it on john's record. How do I fix it?

how does telegram checks if a newly joined user number exists in another user contacts list

I've been trying to research this for a while now, what I want is very simple. I'm trying to compare two phone numbers and checks if they match because I'm tryign to implement something similar to telegram, notify a user if one of his contacts list created an account.
My problem is the following:
If I saved my contact using this format 0791234567 and my contact joined using this number +962791234567 both numbers are the same but the first is using local formats and the second using international formats. Does telegram finds these two numbers as a match and sends me a notification indicating that my contact has joined the network ?
I tried to use google library for parsing the numbers, but unfortunately the library doesn't always parse numbers in any format especially if the region was not provided.
Any hints ? or this is just not possible and all numbers must be of a specific format to be able to find a match ?
I think you should have two fields: ‍counry_code and phone_number, and when registering, login, changing the mobile number and etc, get each of the fields individually.
for example :
id | first_name| last_name | password | country_code |phone_number|...
----------------------------------------------------------------------
1 | alihossein| shahabi | XXXXX | +98 |9377548654
or two tables users and phone_numbers :
id | first_name| last_name | password |
------------------------------------------
1 | alihossein| shahabi | XXXXX |
id | user_id| country_code | phone_number | active
--------------------------------------------------
1 | 1 | +98 | 9377541258 | 1
2 | 1 | +98 | 9377543333 | 0

A rudimentary way to store comments on a proposal webpage using SQLite

I am a software engineer, but I am very new to databases and I am trying to hack up a tool to show some demo.
I have an Apache server which serves a simple web page full of tables. Each row in the table has a proposal id and a link to a web page where the proposal is explained. So just two columns.
----------------------
| id | proposal |
|--------------------
| 1 | foo.html |
| 2 | bar.html |
----------------------
Now, I want to add a third column titled Comments where a user can leave comments.
------------------------------------------------
| id | proposal | Comments |
|-----------------------------------------------
| 1 | foo.html | x: great idea ! |
| | | y: +1 |
| 2 | bar.html | z: not for this release |
------------------------------------------------
I just want to quickly hack up something to show this as a demo and get feedback. I am planning to use SQLite to create a table per id and store the userid, comments in the table. People can add comment at the same time. I am planning to use lock to perform operations on the SQLite database. I am not worried about scaling just want to show and get feedback. Are there any major flaw in this implementation?
There are similar questions. But I am looking for a simplest possible implementation.
Table per ID; why would you want to do that? If you get a large number of proposals, the number of tables can get out of hand very quickly. You just need to keep an id column in the table to keep track of things and keep the number of tables in a sane figure.
The other drawback of using a table for each proposal is that you will not be able to use prepared statements for those, because table names cannot be bound as a parameter.
SQLite assumes the table name is 'a'
Add column
alter table a add column Comments text;
Insert comment
insert into a values (4,"hello.html","New Comment");
You need to provide values for the other two columns along with the new comment.

How to create a Drupal forum reporting/analytics view?

I want to create a page in Drupal to report some basic forum information. I thought I'd use Views, but Views only lets you set one "entity" type per view but forum topics are made up of nodes and comments (aka, topics and replies).
Ideally, I'd like a single view that lists all forum nodes and comments together in a single table (sorted by date), along with a total number of both combined, if possible. Is there a way to do that with Views?
Update: What I'm looking for is something like this:
-------------------------------------------------------
| User | Post | Type | Date |
-------------------------------------------------------
| amy | post text appears here | post | 1/5/01 |
| bob | comment text appears here | comment | 1/5/01 |
| amy | another comment here | comment | 1/5/01 |
| cid | another post appears here | post | 1/4/01 |
| dave | yet another comment here | comment | 1/4/01 |
-------------------------------------------------------
total posts + comments: 5
Not sure what you really want. Either you can display nodes + number of comments or nodes and comments at the same level but then they don't have a total number because they are all separate? Or do you want to show each comment separate together with the number of comments in that thread?
If the latter, that might not be trivial.
Basically, you could create a UNION Select query and query both the node and the comment table. could look like this:
(SELECT 'node' AS type, n.nid as id, n.title as title, nncs.comment_count as comment_count, n.created as timestamp FROM {node} n INNER JOIN {node_comment_statistics} nncs ON n.nid = nncs.nid)
UNION
(SELECT 'comment' AS type, c.cid as id, c.subject as title, cncs.comment_count as comment_count, c.timestamp as timestamp FROM {comments} c INNER JOIN {node_comment_statistics} cncs ON c.nid = cncs.nid)
ORDER BY timestamp DESC LIMIT 10;
That will return a result containing: node/comment | id | title | comment_count | timestamp.
See http://dev.mysql.com/doc/refman/5.1/en/union.html for more information about UNION.
You can then theme that as a table.
Hints:
If you need more data, either extend
the query or use node/comment_load
You could also join {node} in the
second query and use the node title
instead of comment subject
That query is going to be slow
because it will always do a filesort
because you have a union there. It
might actually be faster to execute
two separate queries and then mangle
them together in PHP if you have a
large number of nodes/comments
It turns out the Tracker 2 module provides enough of what I needed.

Resources