primary-key

ReNumber Auto Increment column in SQL

为君一笑 提交于 2019-12-23 19:05:18
问题 Heres my problem. I have an autoincrement primary key in sql table lets say table look like this ID | Name| 1 John 2 Jack 3 Bill 4 Joe Then i delete row 2 Jack ID | Name| 1 John 3 Bill 4 Joe And what I want to achieve is to change id column so the table will look like this ID | Name| 1 John 2 Bill 3 Joe Is there a way to do it ? thanks in advance 回答1: I will never do that but you can: create a new autoincrement primary key named ID2 delete ID column rename ID2 column as ID 回答2: Set identity

Is it possible to add a autoincrement primary index column in full mysql table belated?

孤街醉人 提交于 2019-12-23 15:46:31
问题 Assuming this table with nearly 5 000 000 rows CREATE TABLE `author2book` ( `author_id` int(11) NOT NULL, `book_id` int(11) NOT NULL, KEY `author_id_INDEX` (`author_id`), KEY `paper_id_INDEX` (`book_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci is it possible to add a primary index column id with autoincrement as first place? I expect something like this: CREATE TABLE `author2book` ( `id` int(11) NOT NULL AUTO_INCREMENT, <<<< This is what I try to achieve! `author_id` int

How to change primary key of a record in sqlite?

*爱你&永不变心* 提交于 2019-12-23 13:08:50
问题 I have table that has a TEXT primary key CREATE TABLE tbl1{ a1 TEXT PRIMARY KEY, ... ); (the a1 column is a foreign key inside another table) How can I change values of a1 ? If I do UPDATE tbl1 SET a1 = ? WHERE a1 = ? I get a constrain violation error 回答1: You should never change primary keys; it would be a better idea to use an INTEGER PRIMARY KEY and have the actual URL be a normal data column. If you really want change a key that is the target of a foreign key, you should declare the

Removing a Primary Key (Clustered Index) to increase Insert performance

有些话、适合烂在心里 提交于 2019-12-23 10:47:09
问题 We've been experiencing SQL timeouts and have identified that bottleneck to be an audit table - all tables in our system contain insert, update and delete triggers which cause a new audit record. This means that the audit table is the largest and busiest table in the system. Yet data only goes in, and never comes out (under this system) so no select performance is required. Running a select top 10 returns recently insert records rather than the 'first' records. order by works, of course, but

How to Query to Find out if a Table has a CLUSTERED Primary Key

ぐ巨炮叔叔 提交于 2019-12-23 10:07:30
问题 I found this question, but it doesn't appear to answer the question... SQL Server - How to find if clustered index exists How can I write an IF T-SQL statement to say: IF NOT ([TableName] has a CLUSTERED PK) ALTER TABLE to add the CLUSTERED PK 回答1: Try this IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID('dbo.MdsInventar') AND index_id = 1 AND is_primary_key = 1) ...... The clustered index always has index_id = 1. Of course - if you check like this (with the is_primary

Why we can't have more than one primary key?

核能气质少年 提交于 2019-12-23 09:25:05
问题 I Know there can't be more than 1 primary key in a table but what is the technical reason ? 回答1: Pulled directly from SO: You can only have one primary key, but you can have multiple columns in your primary key. You can also have Unique Indexes on your table, which will work a bit like a primary key in that they will enforce unique values, and will speed up querying of those values. Primary in the context of Primary Key means that it's ranked first in importance. Therefore, there can only be

PHP mysql_insert_id() for MySQL UUID() primary keys?

白昼怎懂夜的黑 提交于 2019-12-23 05:38:10
问题 Is there some equivalent to PHP mysql_insert_id to fetch the last inserted UUID() primary key? (I always get 0. It works for auto_inc integers though) 回答1: No, last_insert_id() only retrieves that last generated auto_increment fields. You'll have to do a select uuid() first, then do an insert using that uuid. However, note that uuids can't be guaranteed to be unique - they're simply very unlikely to collide. If you do require uniqueness, then go with an auto_increment - they'll never be re

hibernate ID increment oracle

独自空忆成欢 提交于 2019-12-23 05:29:10
问题 I managed to let hibernate increment the id of every table by 1 by putting this into every entity class. @Entity public class TestObject implements Serializable{ @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="idgen") @SequenceGenerator( name="idgen", sequenceName="testobject_seq", allocationSize=1, initialValue=1 ) I have two tables which i fill with data manually through the Oracle SQL Developer. After i created the tables. <property name="hibernate.hbm2ddl.auto">create<

How to establish a many to one relationship between 2 tables for a field

断了今生、忘了曾经 提交于 2019-12-23 05:06:52
问题 I am building an database schema for a project and I am bit stuck on this issue. I have 2 tables: USER table: Id Name Contact_ID 1 Arun 2 2 Barath 3 3 Charan 2 4 Dinesh 1 CONTACT table: ID Name Phone Mail 1 Mahesh 1234 Mahesh@Yahoo.com 2 Suresh 54321 Sureh@Google.com 3 Jayesh 9876 Jayesh@Bing.com 4 Ganesh 98754 Gahesh@Safari.com Each of the users in USER will have a contact in CONTACT. If a user has a single contact then I can use a foreign key relationship on Contact_ID in USER and build the

setting MySQL auto_increment to be dependent on two other primary keys

人盡茶涼 提交于 2019-12-23 04:32:58
问题 i'm trying to set up a MySQL database for storing biological data. I have to extract this data from a file and i have a perl script for that. The problem i have is that i need three primary keys in order for them to be unique, and i want one of them to be an auto increment integer. I would like, however, the auto-incremented value to reset each time the combination of the first two keys changes. sequence1 | hit1 | 1 sequence1 | hit1 | 2 sequence1 | hit2 | 1 sequence2 | something | 1 sequence2