首页 \ 问答 \ 这在SQL中是什么样的方法,它确实存在?(What kind of approach is this in SQL, it actually exists? Is it viable/good pratice?)

这在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
更新时间:2021-11-14 18:11

最满意答案

要么使用带有appendString:NSMutableString appendString: ,请使用stringByAppendingString: ,要么使用单个stringWithFormat:构造完整的字符串,请一次性插入所需的值。


Either use an NSMutableString with appendString:, use stringByAppendingString:, or construct the full string with a single stringWithFormat:, plugging in the values you need all at once.

相关问答

更多
  • 使用不同的格式: [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.
  • 你正在调用-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 ...
  • - [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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。