The entity entity code is as follows:
The insert code is as follows:
We only set the value of name and do not assign a value to id, let's take a look at what the generated sql statement is??? , as follows:
exec sp_executesql N'DECLARE @generated_keys table([Id] uniqueidentifier) INSERT [dbo]. [TestTab] ([Name]) OUTPUT inserted. [Id] INTO @generated_keys VALUES (@0) SELECT t.[Id] FROM @generated_keys AS g JOIN [dbo]. [TestTab] AS t ON g.[Id] = t.[Id] WHERE @@ROWCOUNT > 0',N'@0 nvarchar(32)', @0=N' architectwww.itsvse.com'
We found that the INSERT TestTab table only inserts the Name field, does Id have a default value??? We found that
ef has helped me set the default value type of the Id primary key, the default value or binding "(newsequentialid())", and used the newsequentialid() function, which is introduced as follows:
1.:The biggest advantage of the newsequentialid function over the newid function is that if you create an index on a UNIQUEIDENTIFIER field, the new value generated using newid is not fixed, so the new value causes the change in the index B+ tree to be random. If the new value produced by the newsequentialid is regular, then the change of the index B+ tree is regular. Regularity and irregularity lead to performance improvements.
2: UNIQUEIDENTIFIER is a very convenient thing to do as the primary key, which has irreplaceable advantages in operations such as data merging However, due to the decentralization of ordinary GUIDs, if the primary key is added to a clustered index, it will be much less efficient when inserting records
SQL SERVER 2005 adds a new function called NEWSEQUENTIALID, which MSDN explains: Create a GUID on the specified machine that is larger than any GUID previously generated by the function. NEWSEQUENTIALID() cannot be referenced in the query.
Note: This means that it can only be used as the DEFAULT VALUE of a database column, and cannot execute statements like SELECT NEWSEQUENTIALID(). The GUID generated by NEWSEQUENTIALID() is unique in that particular computer only if the computer does not have a network card.
Note: This sentence is wrong, it should be that only when the computer has a network card, the generated GUID is unique in the world You can use NEWSEQUENTIALID() to generate a GUID to reduce page contention on the leaf-level index.
|