primary-key

Best way to reset an Oracle sequence to the next value in an existing column?

烈酒焚心 提交于 2019-11-28 15:38:27
问题 For some reason, people in the past have inserted data without using sequence.NEXTVAL. So when I go to use sequence.NEXTVAL in order to populate a table, I get a PK violation, since that number is already in use in the table. How can I update the next value so that it is usable? Right now, I'm just inserting over and over until it's successful ( INSERT INTO tbl (pk) VALUES (sequence.NEXTVAL) ), and that syncs up the nextval. 回答1: You can temporarily increase the cache size and do one dummy

Reset PostgreSQL primary key to 1

别等时光非礼了梦想. 提交于 2019-11-28 15:30:54
Is there a way to reset the primary key of a PostgreSQL table to start at 1 again on a populated table? Right now it's generating numbers from 1000000 and up. I want it all to reset and start to 1, keeping all my existing data intact. Primary keys that autoincrement (i.e., columns with data type serial primary key ) are associated with a sequence . You can set the next value for any sequence using the setval(<seqname>, <next_value>) function. Note that to actually execute the function by itself you need to use SELECT , like this: SELECT setval(<seqname>, <next_value>) The name of the auto

What is Hash and Range Primary Key?

吃可爱长大的小学妹 提交于 2019-11-28 14:56:47
I am not able to understand what Range primary key is here - http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#WorkingWithTables.primary.key and how does it work? What do they mean by "unordered hash index on the hash attribute and a sorted range index on the range attribute"? mkobit " Hash and Range Primary Key " means that a single row in DynamoDB has a unique primary key made up of both the hash and the range key. For example with a hash key of X and range key of Y , your primary key is effectively XY . You can also have multiple range keys for the same

Information schema and Primary Keys

一世执手 提交于 2019-11-28 13:35:26
How do I just print out a 'primary key' for the column with the primary key? I get 'primary key' for all the columns if the table has a primary key, instead of the one column with the primary key and the other columns as blank in keyType. SELECT c.TABLE_NAME, c.COLUMN_NAME, c.DATA_TYPE, c.Column_default, c.character_maximum_length, c.numeric_precision, c.is_nullable, CASE WHEN u.CONSTRAINT_TYPE = 'PRIMARY KEY' THEN 'primary key' ELSE '' END AS KeyType FROM INFORMATION_SCHEMA.COLUMNS as c LEFT JOIN information_schema.table_constraints as u ON c.table_name = u.table_name ORDER BY table_name

Does MS Access suppress primary key violations on Inserts?

假如想象 提交于 2019-11-28 12:28:24
I am in the process of re-writing an MS Access database to SQL server and have found an strange issue in Access that I am hoping someone can help with. I have a table let's call it 'Main' with a Primary Key on the Account that is indexed and doesn't allow for duplicates. Seems simple enough but my issue is occurring when data is getting Inserted. My INSERT query is (the number of fields have been limited for brevity) INSERT INTO Main (Account, SentDate, Amount) SELECT C.Account, C.SentDate, C.Amount FROM (CALLS C LEFT JOIN Bals B ON C.Account = B.ACCT_ID) LEFT JOIN AggAnt A ON C.Account = A

rails3 bigint primary key

大兔子大兔子 提交于 2019-11-28 12:12:00
I would like to create a bigint (or string or whatever that is not int ) typed primary key field under Rails 3. I have a given structure of data, for example: things ------ id bigint primary_key name char(32) The approach I'm currently trying to push: create_table :things, :id => false do |t| # That prevents the creation of (id int) PK t.integer :id, :limit => 8 # That makes the column type bigint t.string :name, :limit => 32 t.primary_key :id # This is perfectly ignored :-( end The column type will be correct, but the primary key option will not be present with sqlite3 and I suspect that this

Alter Column datatype with primary key

微笑、不失礼 提交于 2019-11-28 12:08:42
I have a ReferenceID varchar(6) column in over 80 different tables. I need to extend this to a varchar(8) throughout the db following a change implemented by the government organisation that assigns the IDs. I was hoping to declare a cursor to get the table names as follows: DECLARE @TableName AS VARCHAR(200) DECLARE TableCursor CURSOR LOCAL READ_ONLY FOR SELECT t.name AS TableName FROM sys.columns c JOIN sys.tables t ON c.object_id = t.object_id WHERE c.name = 'ReferenceID' OPEN TableCursor FETCH NEXT FROM TableCursor INTO @TableName and then edit the type as follows: ALTER TABLE @TableName

Attaching an entity of type failed because another entity of the same type already has the same primary key value.

走远了吗. 提交于 2019-11-28 11:29:20
Let me quickly describe my problem. I have 5 databases for 5 customers and each has the same table called SubnetSettings . I already created a dropdownlist to select a customer and will shows up the SubnetSetting table which belong to selected customer and allow me to create, edit and delete. I can create, delete without problem but when I want to edit the data it brings the error: Server Error in '/TMS' Application. Attaching an entity of type 'CFS.Domain.Entities.SubnetSettings' failed because another entity of the same type already has the same primary key value. This can happen when using

Insert inserted id to another table

北城以北 提交于 2019-11-28 11:03:19
问题 Here's the scenario: create table a ( id serial primary key, val text ); create table b ( id serial primary key, a_id integer references a(id) ); create rule a_inserted as on insert to a do also insert into b (a_id) values (new.id); I'm trying to create a record in b referencing to a on insertion to a table. But what I get is that new.id is null, as it's automatically generated from a sequence. I also tried a trigger AFTER insert FOR EACH ROW , but result was the same. Any way to work this

Negative Primary Keys

我只是一个虾纸丫 提交于 2019-11-28 10:49:10
Are there any repercussions using Negative Primary Keys for tables (Identity Increment -1, Identity Seed -1 in SQL Server 2005)? The reason for this is we're creating a new database to replace an existing one. There are similar tables between the two databases and we'd like the "source" of the information to be transparent to our applications. The approach is to create views that unions tables from both databases. Negative PKs ensures the identities don't overlap. Like others have said, the database is fine with this. But it would be a problems for a .NET application that uses DataSet