sql server - Possible to implement a manual increment with just simple SQL INSERT? -
I have a primary key that I do not want to automatically increment (for various reasons) and therefore I have a method that Enhances the field when I INSERT bus, I mean without stored procedures and without triggers, so a series of SQL commands (preferably a command)
Here I have tried to:
include the BEGIN TRAN in Table 1 (id, data_field) values ((selection (maximum (id) + 1 ) From Table 1), '[Blob of Data]'); Comtrate; * Data for using common names and identifiers However, when executed, command errors are saying that
"This reference Subcategories are not allowed in
So, how can I do this / what am I doing?
Edit: Since it's similar Has been under consideration, the table is guaranteed to be at least 1 row in advance.
Do you think that the collision should be correct?
You need to do something like this and this can lead to deadlock, so you are trying to fulfill it very definite
DECLARE @id int (trailer), 1 table (ID, data_field) value (@ ID, '[Blob of data]') COMMIT TRANS < P> To illustrate the collision, I have provided some code First create this table and insert a line
B Go Table table 1 (id int primary key faucet, data_fill char (100)) Insert table 1 values (1, '[data blocks]') Go Now two query windows Open and turn it on at the same time
Announce @i int set @i = 1 while @ i & lt; Start 10000 initially Select Table 1 (id, data_field) MAX (id) + 1, '[Blob of Data]' Table 1 with Committed Train; Set = i = @ i + 1 end You will see a group of these
Server: Message 2627, Level 14, State 1, line 7 primary violation key The hindrance 'PK__Table 1__3213E 83F2962141D' can not contain the duplicate key in the object 'dbo.Table1' has been terminated.
Comments
Post a Comment