newid()的妙用

    技术2022-05-19  53

    --生成测试数据SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[test](    [name] [varchar](20NULL,    [quarter] [int] NULL,    [profile] [int] NULL,    [dates] [smallint] NULL,    [ID] [int] IDENTITY(1,1NOT NULLCONSTRAINT [PK_test] PRIMARY KEY CLUSTERED (    [ID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ONON [PRIMARY]ON [PRIMARY]GOSET ANSI_PADDING OFFGOSET IDENTITY_INSERT [dbo].[test] ONINSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'a'110004211)INSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'Aa'220004212)INSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'AA'340004213)INSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'a'450004214)INSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'b'130004215)INSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'b'235004216)INSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'b'342004217)INSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'b'455004218)INSERT [dbo].[test] ([name][quarter][profile][dates][ID]VALUES (N'a'110004219)SET IDENTITY_INSERT [dbo].[test] OFF

     

     --从数据库中随机取出N条记录的方法:newid()

    select   top   5   *   from  test select   top   5   *   from  test  order   by   newid ()

     

    (图:效果图) 


    最新回复(0)