Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Change
CREATE TABLE [dbo].[Table1]( [id] uniqueidentifier NOT NULL , [id2] uniqueidentifier NOT NULL, [name] nvarchar(max) NOT NULL CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED ( [id] ASC )) GO CREATE NONCLUSTERED INDEX [IX_Table2_ID2] ON [dbo].[Table1] ( [id2] ASC ) ALTER TABLE [dbo].[Table1] ADD CONSTRAINT [DF_Id] DEFAULT (newsequentialid()) FOR [id] GO CREATE TABLE [dbo].[Table2]( [id] uniqueidentifier NOT NULL, [name] varchar(10) CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED ( [id] ASC )) GO ALTER TABLE [dbo].[Table2] ADD CONSTRAINT [DF_Id2] DEFAULT (newsequentialid()) FOR [id] CREATE NONCLUSTERED INDEX [ndx_name] ON [dbo].[Table2] ( [name] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY] GO Declare @loop int = 1 while @loop<=10 begin insert into Table2 ([name]) Values(char((rand()*25 + 65))+char((rand()*25 + 65))+char((rand()*25 + 65))+char((rand()*25 + 65))) set @loop = @loop+1 end set @loop = 1 while @loop<2000 begin insert into Table1 (ID2, [name]) select ID,char((rand()*25 + 65))+char((rand()*25 + 65))+char((rand()*25 + 65))+char((rand()*25 + 65)) from Table2 set @loop = @loop+1 end select top 100 table1.Name,table2.Name from table1 WITH (NOLOCK) left join table2 on table1.ID2= table2.ID order by table2.ID desc,table1.ID desc select top 100 table1.Name,table2.Name from table1 WITH (NOLOCK) left join table2 on table1.ID2= table2.ID order by table2.name desc,table1.ID desc
run
|
edit
|
history
|
help
0
bc160401693
BT SQL Project
Using pre-built schema in sql server
/Users/svetlanakanevskaa/Downloads/ACDB.sql
a
adbms 0
kirthi
New
dk
2021-03-09_LeetCodeSQL