如何自动增加一个varchar

How to autoincrement a varchar(如何自动增加一个varchar)
本文介绍了如何自动增加一个varchar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在一张表中创建一个像c0001、c0002"和供应商s0001、s0002"这样的主键吗?

Can I make a primary key like 'c0001, c0002' and for supplier 's0001, s0002' in one table?

推荐答案

  1. 数据库设计的理念是将每个数据元素分开.每个元素都有自己的数据类型、约束和规则.c0002 不是一个字段,而是两个.与 XXXnnn 或其他类似.这是不正确的,它将严重限制您使用数据的能力,以及使用数据库功能和设施的能力.

  1. The idea in database design, is to keep each data element separate. And each element has its own datatype, constraints and rules. That c0002 is not one field, but two. Same with XXXnnn or whatever. It is incorrect , and it will severely limit your ability to use the data, and use database features and facilities.

将其分解为两个离散的数据项:
column_1 CHAR(1)
column_2 INTEGER

Break it up into two discrete data items:
column_1 CHAR(1)
column_2 INTEGER

然后在 column_2

是的,你的主键可以是 (column_1, column_2),所以你没有失去 c0002 对你的任何意义.

And yes, your Primary Key can be (column_1, column_2), so you have not lost whatever meaning c0002 has for you.

永远不要将供应商和客户(无论c"和s"是什么意思)放在同一张表中.如果这样做,您将没有数据库表,您将拥有一个平面文件.以及随之而来的各种问题和限制.

Never place suppliers and customers (whatever "c" and "s" means) in the same table. If you do that, you will not have a database table, you will have a flat file. And various problems and limitations consequent to that.

这意味着,规范化数据.你最终会得到:

That means, Normalise the data. You will end up with:

  • 一个用于 PersonOrganisation 的表格,其中包含公共数据(Name, Address...)
  • Customer 的一张表,其中包含客户特定的数据 (CreditLimit...)
  • 一个用于 Supplier 的表格,其中包含特定于供应商的数据(PaymentTerms...)
  • 没有歧义或可选的列,因此没有空值
  • 对使用或 SQL 函数没有限制
    .
  • one table for Person or Organisation containing the common data (Name, Address...)
  • one table for Customer containing customer-specific data (CreditLimit...)
  • one table for Supplier containing supplier-specific data (PaymentTerms...)
  • no ambiguous or optional columns, therefore no Nulls
  • no limitations on use or SQL functions
    .

当您需要添加列时,您只在需要的地方添加,而不会影响平面文件的所有其他起诉.影响范围仅限于变更范围.

And when you need to add columns, you do it only where it is required, without affecting all the other sues of the flat file. The scope of effect is limited to the scope of change.

这篇关于如何自动增加一个varchar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)