--newid()可以在查询的时候自动生成Guid列
select top 10 *,newid() as Random from ywle where ywlename='001' ordey by Random
--创建对应的列 用 uniqueidentifier 类型
IF NOT EXISTS ( SELECT * FROM dbo.SysObjects WHERE ID = object_id(N'[RMA_ExchangeOrderAddTempInfo]') AND OBJECTPROPERTY(ID, 'IsTable') = 1 ) BEGIN SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON CREATE TABLE [dbo].[RMA_ExchangeOrderAddTempInfo]( [Id] [int] IDENTITY(1,1) NOT NULL, RandNum uniqueidentifier NULL, ) END GO
/// <summary> /// 随机数作主键(接收和传参在后台用Guid类型) /// </summary> public Guid RandNum { get; set; }