Can we have more than one ID column in a table?

Is it possible to specify 2 id column in the table. If not? if so why

0


a source to share


3 answers


"identity column" is NOT a SQL concept. You should be referring to some specific implementation with its own quirks and extension, not SQL in general as your tag claims; edit and re-tag your question. (If you mean "Microsoft SQL Server" the answer is "no" because Microsoft thought it didn't make sense [and they were damned right this time! -)] ").



+1


a source


Depends on what you mean by identification

There are several specific constructs, such as "rowid", "oid", etc., which aim to uniquely define a row using a value generated by the DBMS. On most dbms systems, you have one and only one of these lines.



The "identity" of a row can also mean a primary key. ANSI sql supports multi-column primary keys, in most DBMS you can include any or all suitable columns in the primary key. Then the id is made up of a combination of all the columns in the primary key, but that's big, but logically it still represents a single id.

You can specify a "unique" constraint *** s *** on any or all matching columns, each constant can be considered a "person" in itself, so the answer to your question is probably "yes" - but I've never seen real implementing this.

+1


a source


Other people point out that "identity" is not a type in the SQL standard are correct.

The IBM Informix Dynamic Server (IDS) supports the SERIAL, SERIAL8, and BIGSERIAL types. These are integer types with additional properties that, if you insert null into them (or if you do not specify the value to be inserted), the next higher previously unused value is applied instead. This is consistent with another DBMS calling the identity column. (IDS also provides sequences.)

One curiosity (quirk) is that you are allowed to have both a SERIAL column and a SERIAL8 or BIGSERIAL column in the same table. This is not recommended and unwise; however, this is not prohibited.

Most DBMSs do not allow two separate "id" columns in the same table.

0


a source







All Articles