identity-column

Alter exisitng int column to identity in sybase

时光总嘲笑我的痴心妄想 提交于 2019-12-23 12:25:58
问题 Sybase 12.5 I have an existing table in production that needs it's PK int column to be altered such that it is auto populated - when the table was created it would ideally have had the ID column created as an Identity. This ID column is a foreign key in multiple other tables so deleting the table and starting again isn't an option. Problem is, I can't set the PK as an IDENTITY, and creating a temp column with the current values and copying these to a new IDENTITY column is also failing. As

Changing Identity Seed in SQL Server (Permanently!)

余生长醉 提交于 2019-12-23 07:31:50
问题 Is there any way of changing the identity seed for an identity column permanently? Using DBCC CHECKIDENT just seems to set the last_value. If the table is truncated all values are reset. dbcc checkident ('__Test_SeedIdent', reseed, 1000) select name, seed_value, increment_value, last_value from sys.identity_columns where [object_id] = OBJECT_ID('__Test_SeedIdent'); returns name seed_value increment_value last_value ------------------------------------------------- idIdent 1 1 1000 I was

Maintaining a foreign key relationship when inserting into tables with autoincrementing Id's

爱⌒轻易说出口 提交于 2019-12-22 08:28:30
问题 I have two tables: Defect and DefectData. Each Defect may or may not have one or many DefectData. As such DefectData has a DefectId column as a foreign-key. The Id in both tables is an autoincrementing identity. The problem I am having is that when I want to insert a new Defect and its DefectData the Defect is inserted first and gets an Id, but I don't know what that Id is to give to DefectData. My solution is to then select from defects matching inserted data to get the Id. Insert Defect Get

How to reseed an an auto increment column in a SQLite database?

妖精的绣舞 提交于 2019-12-21 07:27:09
问题 Is it possible to reseed an auto increment column in a SQLite database, and if so, how is this done? ie. The equivalent of DBCC CHECKIDENT ('MyTable', RESEED, 1) in SQL Server. 回答1: In SQLite there is a table named SQLITE_SEQUENCE, which tracks the largest RowId value that a table has. You can do insert, updates and deletes on this table. For example, to mimic similar functionality as the TRUNCATE TABLE statement SQL Server you could something like: DELETE FROM MyTableName; DELETE FROM SQLITE

Get Identity Field out of KeyMembers

冷暖自知 提交于 2019-12-20 03:21:57
问题 I would like to get the KeyMembers where I have set in the Edmx the StoreGeneratedPattern to Identity is there a way to do this? I can get the KeyMembers with this code: private static IEnumerable<EdmMember> GetKeyMembers(string entityName) { var objectContext = EntityModel.ObjectContext; var metaData = objectContext .MetadataWorkspace .GetEntityContainer(objectContext.DefaultContainerName, DataSpace.CSpace) .BaseEntitySets .FirstOrDefault(x => x.ElementType.Name == entityName); return

How do I set Identity seed on an ID column using Entity Framework 4 code first with SQL Compact 4?

痴心易碎 提交于 2019-12-18 09:15:33
问题 I am having some problem setting the Identity Seed on the Id column in SQL Compact 4 using the code first approach. I have tried this context.Database.ExecuteSqlCommand("DBCC CHECKIDENT ('Members', RESEED, 100001"); but this is not working in Sql Compact. MyDbContext: protected override void OnModelCreating(DbModelBuilder modelBuilder) { SetupMemberEntity(modelBuilder); } private static void SetupMemberEntity(DbModelBuilder modelBuilder) { modelBuilder.Entity<Member>().Property(m => m.Id); //

Returning the value of identity column after insertion in Oracle

血红的双手。 提交于 2019-12-18 06:17:12
问题 How do I return the value of an identity column (id) in Oracle 12c after insertion? Seems like most of the approaches out there uses sequence to get back the id of the inserted item. 回答1: Simply use the RETURNING clause. For example - RETURNING identity_id INTO variable_id; Test case - SQL> set serveroutput on SQL> CREATE TABLE t 2 (ID NUMBER GENERATED ALWAYS AS IDENTITY, text VARCHAR2(50) 3 ); Table created. SQL> SQL> DECLARE 2 var_id NUMBER; 3 BEGIN 4 INSERT INTO t 5 (text 6 ) VALUES 7 (

Clustered indexes on non-identity columns to speed up bulk inserts?

北慕城南 提交于 2019-12-17 19:39:36
问题 My two questions are: Can I use clustered indexes to speed up bulk inserts in big tables? Can I then still efficiently use foreign key relationships if my IDENTITY column is not the clustered index anymore? To elaborate, I have a database with a couple of very big (between 100-1000 mln rows) tables containing company data. Typically there is data about 20-40 companies in such a table, each as their own "chunk" marked by "CompanyIdentifier" (INT). Also, every company has about 20 departments,

Multiple insert SQL oracle

陌路散爱 提交于 2019-12-17 13:23:58
问题 How do you do multiple insert with SQL in Oracle 12c when you have an identity column? INSERT ALL INTO Table1 (Column2) Values (1) INTO Table1 (Column2) Values (2) SELECT * FROM dual; where Table1 has column1 as an identity, will set the identity column to have the same value which violates the primary key constraint. CREATE TABLE Table1 ( Table1Id NUMBER GENERATED ALWAYS AS IDENTITY, column2 VARCHAR2(255), column3 NUMBER, PRIMARY KEY (Table1Id) ); INSERT ALL INTO Table1 (column2, column3)

SQL Server - how to ensure identity fields increment correctly even in case of rollback

故事扮演 提交于 2019-12-14 01:52:20
问题 In SQL Server, if a transaction involving the inserting of a new row gets rolled back, a number is skipped in the identity field. For example, if the highest ID in the Foos table is 99, then we try to insert a new Foo record but roll back, then ID 100 gets 'used up' and the next Foo row will be numbered 101. Is there any way this behaviour can be changed so that identity fields are guaranteed to be sequential? 回答1: What you are after will never work with identity columns. They are designed to