relational-database

How to implement Twitter retweet action in my database

拟墨画扇 提交于 2019-12-04 12:20:00
问题 I am implementing web application similar to Twitter. I need to implement 'retweet' action, and one tweet can by retweeted by one person multiple times . I have a basic 'tweets' table that have columns for: Tweets: tweet_id | tweet_text | tweet_date_created | tweet_user_id (where tweet_id is primary key for tweets, tweet_text contains tweet text, tweet_date_created is the DateTime when tweet was created and tweet_user_id is the foreign key to users table and identifies user who has created

phpMyAdmin - Error: relational features are disabled

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 11:59:47
问题 When I want to create a relation between two tables in designer mode with phpMyAdmin 4.3.8, it gives me an error saying: Error: relational features are disabled! When I try it with 4.1.4, it works just fine. I can't seem to find where I should change the settings to be able to create relations in designer mode. Any idea? Thanks in advance! 回答1: Convert your table/db engine to InnoDB using ALTER TABLE table_name ENGINE=InnoDB; 回答2: I had the same issue, it was because I didn't have a database

How to properly relate items to pricing data, taking price change history into account

时光总嘲笑我的痴心妄想 提交于 2019-12-04 11:04:36
Virtually all POS systems record the price of an item directly to the transactions table at the time of the sale since that price may change at a later date, but the price it sold at should remain the same. I'm wondering how you would setup pricing table(s) that keep a history of price changes, so that you can relate the transactions to that table based on the item and the time it was sold in order to get the correct price? I think anyone who's ever worked with POS systems will understand what I'm talking about here, but if my question is unclear let me know and I will try to explain better. I

Entity Framework - Updating relationship by changing foreign key

巧了我就是萌 提交于 2019-12-04 11:02:55
问题 I have the two following models and DbContext: public class TestDbContext : DbContext { public IDbSet<Person> People { get; set; } public IDbSet<Car> Cars { get; set; } } public class Person { public Person() { ID = Guid.NewGuid(); } public Guid ID { get; set; } public string Name { get; set; } public virtual List<Car> Cars { get; set; } } public class Car { public Car() { ID = Guid.NewGuid(); } public Guid ID { get; set; } public string Name { get; set; } public virtual Person Owner { get;

How to store taxes in database?

泪湿孤枕 提交于 2019-12-04 10:17:44
I need to add per-province/state taxes to my project. I'm debating whether I should add a many-to-many relationship between Provinces and Taxes, or just add a tax1_name, tax1_rate, tax2_name, tax2_rate to each province. I don't think any place has more than 2 taxes? I will also need to store the tax rate at the time of purchase with each invoice. So my options are add 2 many-to-many tables, or add 8 fields. Which would you go with, and why? Or I could just have 1 combined tax. I don't think it would be too bad if it showed on the invoice as "GST + PST". This would solve the issue with stupid

Why is multi-value field a bad idea in relational databases

╄→гoц情女王★ 提交于 2019-12-04 09:32:34
Having been working with Mongodb and Solr/Lucene, I am starting to wonder why multi-value field for relational databases are (generally) considered an bad idea? I am aware of the theoretical foundation of relational database and normalization . In practice, however, I ran into many use cases where I end up using an meta table of key-value pairs to supplement the main table, such as in the cases of tagging, where I wish I don't have to make multiple joins to look up the data. Or where requirements suddenly changed from having to support an single author to multiple authors per article. So, what

Why would I want to use a non-relational database?

房东的猫 提交于 2019-12-04 08:42:37
The latest craze in databases seems to be centered around non-relational databases. Why? It seems kind of counterproductive. For example, it makes much more sense to me to express my data in a relational way (example code in Django + SQL for tables): class Post(models.Model): name = models.CharField() created = models.DateTimeField(auto_now_create = True) class Comment(models.Model): text = models.TextField() post = models.ForeignKey('Post') created = models.DateTimeField(auto_now_create = True) SQL: create table post (id int primary key auto_increment, name varchar, created datetime); create

Relational to NoSQL Database

…衆ロ難τιáo~ 提交于 2019-12-04 07:41:26
This question is for all NoSQL and specially mongoDB experts out there. I started by designing a relational DB for a project but client wants us to use a DB that can easily scale. To achieve this we have decided to use mongoDB. These days I am having trouble mapping my relational model for NoSQL. I have a users table which has a many-to-many relation with a lot of other tables as illustrated below: I have a few options when converting it for mongoDB: Option 1 (with complete rows in users): users:{ _id:<user_id>, battles:{[battle1, battle2, ...]}, items:{[item1, item2, ...]}, locations:{

postgresql foreign key syntax

眉间皱痕 提交于 2019-12-04 07:23:00
问题 I have 2 tables as you will see in my posgresql code below. The first table students has 2 columns, one for student_name and the other student_id which is the primary key. In my second table called tests, this has 4 columns, one for subject_id, one for the subject_name, then one for a student with the higest score in a subject which is highestStudent_id. am trying to make highestStudent_id refer to student_id in my students table. This is the code i have below , am not sure if the syntax is

Postgresql delete multiple rows from multiple tables

女生的网名这么多〃 提交于 2019-12-04 07:11:39
Consider 2 or more tables: users (id, firstname, lastname) orders (orderid, userid, orderdate, total) I wish to delete all users and their orders that match first name ' Sam '. In mysql, I usually do left join. In this example userid is unknown to us. What is the correct format of the query? Juan Carlos Oropeza http://www.postgresql.org/docs/current/static/sql-delete.html DELETE FROM orders o USING users u WHERE o.userid = u.id and u.firstname = 'Sam'; DELETE FROM users u WHERE u.firstname = 'Sam'; You can also create the table with ON delete cascade http://www.postgresql.org/docs/current