Designing a schema to store the last notifications for each user - sql-server

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 hours ago.
This post was edited and submitted for review 3 hours ago.
Improve this question
I need to store the last 10 notifications of each user in my system. Which of the following design is better for a write-intensive workload?
The first design:
userId bigint NOT NULL,
notificationId int NOT NULL,
isOpened bit NOT NULL
The second design:
userId bigint NOT NULL,
notification string NOT NULL
In the first schema design, I have to schedule a job at midnight to cut off data older than the last 10 notifications.
In the second schema, I will store the notifications as a JSON string like [{"notificationId": 1, "isOpened": false}, {"notificationId": 2, "isOpened": true}]. This would allow me to remove the first notification when I receive a new one to maintain the correct numbers.

Related

Employee Hierarchy at different levels [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 5 tables in my database called Employee, Company, Team, Locations and Position. Now Positions are assigned to employee on each of these levels i.e. to Company, Team and Location. To resolve this I have created 3 tables called CompanyPosition, TeamPosition and LocationPosition. An employee can hold multiple positions in each of these level i.e I can be a CEO, MD at company level etc.
Now I have a situation that in each of these position tables an employee can hold multiple positions and he will reports to someone holding multiple positions, but to only one of position at a time.
I am thinking of creating a new column called ReportstoPositionId in each of these tables CompanyPosition, TeamPosition and LocationPosition to solve this problem.
Can anyone suggest me that I am going in right direction or it can have some problem now or in furture.

Oracle - Why is the dummy column in DUAL type varchar2(1) and not an integer? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
SELECT * FROM dual;
This table has 1 column called Dummy of type varchar2(1)
Anyone who knows why the column is varchar2 and not an integer?
It's just convenience table. Do you really use DUMMY column that much?
SELECT 1 DUMMY FROM DUAL
And you have integer.
Btw. if you ask why the name 'DUAL'? Back in the days it had two rows.

Naming my DB tables - Suggestions? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a couple of properties in my sql server SLS.Customer table which are references to other tables. I can't think of proper names for those tables. Help please :)
Table1: Contains the "How did you hear about us" values. (Example records: Through a friend, Advertisement, Seminar x, conference y, etc.)
Table2: Contains various reasons a customer refused to buy our product.
Table3: Contains the industry/business type a customer belongs to. (I thought of CustomerIndustry or just Industry but it sounds strange!!
Table4: Contains contact info of the person(s) related to a customer entity (specially if the customer is a company, rather than an individual, I need contact info of a person in charge). This is different from the tables PartyAddress and PartyPhones
As the question is suggestion based. I just put some suggestions here.
Table1:
RefererInfo
RefererDetails
Table2:
backlogReasons
backlogInfo
backlogDetails
Table3:
CustomerCategory
CustomerBackground
Table5:
PersonInChargeForParty
ContactsForParty

Database design questions, what do you think? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have the following entities in my system: COMPANY, POSITION, APPLICANTS. There is many to many relationships between POSITION and APPLICANTS, but the current model does not show that there is many to many relationships between COMPANY and APPLICANTS.
Does it make sense to you to have a join table foo that has the company_id, position_id and applicant_id or i should have a table that joins COMPANY and POSITION and another that joins POSITION and APPLICANTS?
I don't think so. You can get APPLICANT for a given COMPANY via JOIN with POSITION.
I think a relationship between a COMPANY and an individual becomes significant when they shift from APPLICANT to EMPLOYEE. I would not model it as you propose.

Creating tables at Runtime [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I have 2 tables User and User_Event
User
id PK BIGINT
User_Event
event_id PK BIGINT
user_id FK References User.id
Should I create above tables before runtime
OR
should I create table "User_Event" for each Existing user at runtime (In this case table name would be like this
User_Event_user001,User_Event_user002....)
Now my questions is
1. Which design is better?
2. which implementation is faster?
For both questions, the best answer is to have an invariant database structure.
Modifying/creating the tables is a lot of work for databases, as they are designed for managing DATA inside the defined structures (tables, views).
It is very rare that changing the structure on the fly is pertinent, and even less effective.
--> create tables before runtime !
I don't know what is purpose of your system but classical implementation is to have one table User_Event and store data about all users in this table. If you want to get info for one user you should use query:
SELECT event_id FROM User_Event where user_id=<your user_id>;

Resources