database-design

understanding how a primary key works & how to use it

假装没事ソ 提交于 2020-01-15 07:01:23
问题 I am using SQL Server and creating a table (example is at the very bottom of this question). However I am having some issues understanding how primary keys actually work & how to use them properly. So I know a primary key ensures all the rows in a table are unique and that a primary key can't be null. I also read this page index basics - simple talk on indices and how indices are organised in a b-tree structure. So in my table for a row to have a unique value I would have to use the first 3

Surrogate Key vs Natural Key for EF

一世执手 提交于 2020-01-15 05:24:05
问题 My co-worker and I are trying to decide which is a better way to design the schema and keys for two database tables. One is a lookup-table that rarely changes. It has about 700 rows. The other table references the lookup-table. This table will have many thousand rows over time. In Design B, the lookup table has a primary key consisting of 3 varchars. The other table has a primary key consisting of the same 3 varchars with the addition of two date fields. In Design A, the 3 varchars are

String as primary KEY?

筅森魡賤 提交于 2020-01-15 04:02:12
问题 I have this database structure CREATE TABLE `productinfo` ( `ProductID` int(11) NOT NULL AUTO_INCREMENT, `ProductName` varchar(255) NOT NULL, `ProductImage` varchar(255) NOT NULL, `CategoryID` int(11) NOT NULL, `SubCategoryID` int(11) NOT NULL, `ProductBrief` varchar(255) NOT NULL, `Features` text NOT NULL, `Specifications` text NOT NULL, `Reviews` text NOT NULL, `Price` varchar(255) NOT NULL, `Status` tinyint(4) NOT NULL, PRIMARY KEY (`ProductID`) ) ENGINE=MyISAM AUTO_INCREMENT=12 DEFAULT

SQL prototype design: facing silent truncation of data using varchar(N) — any better alternatives? (Teradata)

蓝咒 提交于 2020-01-15 04:01:46
问题 Situation: varchar(20) seems to truncate silently in Teradata and not to expand or complain when encountering strings larger than 20 characters long... This is a bit of a surprise as I expected either automatic expansion of the column to fit larger strings, say 30 characters, OR for an error to be thrown if a larger string were encountered. Silent truncation seems to get me the worst of all worlds... Complication: For my application (prototype analytics design) I don't know in advance how

Users in database server or database tables

不打扰是莪最后的温柔 提交于 2020-01-14 19:21:05
问题 I came across an interesting issue about client server application design. We have this browser based management application where it has many users using the system. So obvisously within that application we have an user management module within it. I have always thought having an user table in the database to keep all the login details was good enough. However, a senior developer said user management should be done in the database server layer if not then is poorly designed. What he meant

InnoDB disk usage overhead

南笙酒味 提交于 2020-01-14 09:21:51
问题 I have a table that holds two 32bit integers. These two integers are used to create the clustered index. The SQL for creating the table is as follows, CREATE TABLE `a` ( `var1` int(10) unsigned NOT NULL, `var2` int(10) unsigned NOT NULL, PRIMARY KEY (`var2`,`var1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin; There are 6921338 rows in this table (retrieved by using SELECT COUNT(*) FROM a ) The table uses 358580224 bytes of space (retrieved by using SHOW TABLE STATUS ) According to

Database design for an online quiz

故事扮演 提交于 2020-01-14 07:08:27
问题 I am designing an online math quiz for a college project and having some trouble with designing my database. The basic idea of the website is as follows: A teacher, once registered may log in and add questions to their account. They can choose between making the questions multiple choice OR true or false. They can also choose between making their questions public or private. (If they choose to make the questions public, other teachers may view the questions.) At any time the teacher may

Like and Dislike System for Posts

六眼飞鱼酱① 提交于 2020-01-14 06:23:13
问题 I want to include a like/dislike system similar to Facebook and so far, I have set the like/dislike columns as a 'text' type. This is so that I can add the id for the user(s) who liked/disliked a post. Would that be the best way of doing it? Also, in addition to the question above, how would I stop a user pressing the like and dislike button again? Since, once a user has liked a post, it should display an unlike/undislike option? A concept/idea would be great of how to do this. 回答1: While it

Designing a database that handles inventory tracking with product variations

為{幸葍}努か 提交于 2020-01-14 06:19:06
问题 I am designing a database for a project that handles inventory management for shops. Basically, each Product can have the variations Color , and Size , and obviously, the number of products (stock) of each possible variation will vary. Example: [ { "product": "Plain T-Shirt", "color": "Red", "size": "Medium", "stock": 10, }, { "product": "Plain T-Shirt", "color": "Red", "size": "Large", "stock": 2, }, ] Here, the same product (Plain T-Shirt) has different stocks for different variations. As

ER diagram - Project, Task and Employee

只愿长相守 提交于 2020-01-14 06:03:30
问题 UPDATE: Company can have multiple Projects and Company also have Employees. An employee can only have one Company and a Project can also have only one company. A project has several tasks. Out of these tasks, an Employee will only be assigned to some of the tasks. The employee can only be assigned tasks for project that he/she is assigned to. Please review the following and help on how I should create the database design and the final entity model UPDATED DIAGRAM based on the two comments: If