这在SQL中是什么样的方法,它确实存在?(What kind of approach is this in SQL, it actually exists? Is it viable/good pratice?)
我们的一位老师给了我们以下挑战:
“使用以下原则创建数据库模式:您不能更改任何表上的任何值,只能添加新值。”
我带来了以下架构:
CREATE TABLE TRANSACTIONS(ID PRIMARY KEY, TRANSACTION_TYPE_FK, DATE); CREATE TABLE TRANSACTION_TYPE(ID PRIMARY KEY, NAME); CREATE TABLE PRODUCTS_TRANSACTIONS(ID_PROD_FK, ID_TRANS_FK, MONEY, QTY); CREATE TABLE PRODUCTS(ID PRIMARY KEY, NAME, PRICE_FK ); CREATE TABLE PRICES(ID PRIMARY KEY, DATE, DETAILS);
这只是一个概念证明。 基本上一切都基于交易。
交易可以是进入,退出和移动产品以及进出货币。
我可以根据交易控制我的数量和现金。
如果交易仅涉及金钱或交易中存在“折扣”或“税”,则使用PRODUCTS_TRANSACTIONS“MONEY”字段。
产品表有一个名为“价格”的“子”表,它存储所有价格变化,“详细信息”字段用于“成本价”等注释。
我做得很快,对于任何不一致我很抱歉。
我喜欢这种方法,我有点像SQL的新手所以我真的想知道这种方法是否有名称,如果它是可行的性能或良好的实践。
我的想法是在制作新事务时创建一个View并“更新”它,因为没有什么需要“更新”我只需要向View添加新行。
我目前病得很重,所以我不能上大学来解决我的疑虑。
在此先感谢您的帮助
One of our teachers gave us the following challenge:
"Make a Database schema with the following principle: you can't change any values on any table, only add new ones."
I came with the following schema:
CREATE TABLE TRANSACTIONS(ID PRIMARY KEY, TRANSACTION_TYPE_FK, DATE); CREATE TABLE TRANSACTION_TYPE(ID PRIMARY KEY, NAME); CREATE TABLE PRODUCTS_TRANSACTIONS(ID_PROD_FK, ID_TRANS_FK, MONEY, QTY); CREATE TABLE PRODUCTS(ID PRIMARY KEY, NAME, PRICE_FK ); CREATE TABLE PRICES(ID PRIMARY KEY, DATE, DETAILS);
It's just a proof of concept. Basically everything is based on transactions.
Transactions can be Entry, Exit and Move Products and In & Out Money.
I can control my quantities and cash based on transactions.
The PRODUCTS_TRANSACTIONS "MONEY" field is used if a transaction involves money only or there are "discounts" or "taxes" on the transaction.
The Products Table has a "child" table called "prices", it storages all the price changes , the "details" field is for annotations like "Cost Price" etc.
I made it very quick, I am sorry for any inconsistency.
I liked this kind of approach, I am kinda of a newbie with SQL so I really wanted to know if this approach has a name and if it is viable perfomance-wise or a good pratice.
My idea is making a View and "update" it whenever a new transaction is made, since nothing needs to be "updated" I only need to add new rows to the View.
I am currently very sick, so I can't go to college to remedy my doubts.
Thanks in advance for any help
原文:https://stackoverflow.com/questions/39364311
最满意答案
要么使用带有
appendString:
的NSMutableString
appendString:
,请使用stringByAppendingString:
,要么使用单个stringWithFormat:
构造完整的字符串,请一次性插入所需的值。Either use an
NSMutableString
withappendString:
, usestringByAppendingString:
, or construct the full string with a singlestringWithFormat:
, plugging in the values you need all at once.
相关问答
更多-
Char to NSString ObjC(Char to NSString ObjC)[2021-07-04]
使用不同的格式: [fileContents appendString:[NSString stringWithFormat:@"\\x%02x", (unsigned)curChar]]; 编辑:为了保存输入,您可以使用appendFormat:正如Nikolai Ruhe现在删除的答案中所指出的那样)。 Use a different format: [fileContents appendString:[NSString stringWithFormat:@"\\x%02x", (unsigned) ... -
仍然建议您复制,因为您想要避免传递可变字符串的东西,然后在不知情的情况下更改它。 一个副本保证你的字符串不会改变。 It is still recommended to copy because you want to avoid something passing a mutable string and then changing it without you knowing. A copy guarantees that the string you have will not change.
-
将从字典对象转换的NSString附加到NSMutableArray(append a NSString converted from dictionary object to NSMutableArray)[2021-11-30]
你正在调用-appendString: with myDate ,它不是一个字符串。 这是一个NSDate 。 您无法将其传递给需要字符串的API。 你需要以某种方式将它转换为字符串。 这可能最好使用NSDateFormatter完成,它可以让您完全控制如何将日期格式化为字符串。 但是出于测试目的,你可以用[myString appendString:[myDate description]]替换你的最后一行,它应该会停止崩溃。 You're calling -appendString: with myDa ... -
您的viewDidLoad需要以小写v开头。 您还应该为您的subtotal字符串声明一个retain属性,然后使用setter来分配它,这样您的视图控制器就有了自己的指向字符串的指针,当它进入自动释放池时不会被意外释放。 在您的头文件中: @property (nonatomic, retain) NSString *subtotal; 在您的实现文件中: -(IBAction)digitPressed:(UIButton *)sender { NSString *digit = [[sende ...
-
好消息! 有一种“计算机科学/数学方法”可以更快地完成这项工作。 您链接到的示例执行线性搜索:它只是从字符串末尾一次切换一个字符,直到它足够短。 因此,它所花费的时间将与字符串的长度成线性比例,而对于长字符串,它将非常慢,正如您所发现的那样。 但是,您可以轻松地将二进制搜索技术应用于字符串。 你可以从中间开始,而不是从最后开始并一次放下一个角色: THIS IS THE STRING THAT YOU WANT TO TRUNCATE ^ 你计算“这就是那个字 ...
-
(Append总是意味着添加到最后,即在中间插入一个字符串。) 如果你只是想构造一个文字字符串,请使用 #define STR1 @"Hello" NSString* str2 = @"Hi..." STR1 @" how r u??"; 要在运行时插入它,您需要将str2转换为可变字符串并调用-insertString:atIndex: NSMutableString* mstr2 = [str2 mutableCopy]; [mstr2 insertString:str1 atIndex:4]; re ...
-
要么使用带有appendString:的NSMutableString appendString: ,请使用stringByAppendingString: ,要么使用单个stringWithFormat:构造完整的字符串,请一次性插入所需的值。 Either use an NSMutableString with appendString:, use stringByAppendingString:, or construct the full string with a single stringWit ...
-
你最好使用另一个NSString方法: - (CGSize)drawAtPoint:(CGPoint)point forWidth:(CGFloat)width withFont:(UIFont *)font lineBreakMode:(UILineBreakMode)lineBreakMode 并将UILineBreakModeTailTruncation指定为lineBreakMode 。 You'd better to us ...
-
将NSString附加到NSMutableString,引发异常(Append a NSString to a NSMutableString, raises an exception)[2023-07-24]
- [NSCFNumber length]:发送到实例0x4b54de0的无法识别的选择器*由于未捕获的异常'NSInvalidArgumentException'而终止app,原因:' - [NSCFNumber length]:无法识别的选择器发送到实例0x4b54de0' 根据异常,看起来objectAtIndex:返回NSNumber而不是NSString 。 如果nid包含数字,则需要先将它们转换为字符串,然后才能将它们传递给appendString : NSUInteger row = [ind ... -
我一直是[NSString stringWithFormat@"%@%@", a, b];的粉丝[NSString stringWithFormat@"%@%@", a, b]; 因为那么你显然会得到一个新的自动释放字符串,并且可以正确处理“a”和“b”。 使用[someDictionary objectForKey:@"some_key"] ,您将获得最初放入该字典的对象类型。 所以盲目地调用stringByAppendingString而不知道该字典中的内容似乎是一个坏主意。 I've always b ...