Home > database >  Test questions, see who can answer
Test questions, see who can answer

Time:10-19

- 1 million data in a User
The CREATE TABLE [User] (
/UserID/int IDENTITY (1, 1) NOT NULL,
[OrganizationID] [int] NOT NULL,
[UserName] [nvarchar] (100) NOT NULL,
["]/nvarchar (Max) is NULL,
)

- [UserSettings] 2 million data in the table
The CREATE TABLE [UserSettings] (
[UserSettingId]/int IDENTITY (1, 1) NOT NULL,
UserId (int) NOT NULL,
[SettingKey] [nvarchar] (100) NOT NULL,
[SettingValue] [nvarchar] (500) NOT NULL
)

- if the user table have user1 and user2, please use different ways to find user1 and user2 setting information, and analyze the advantages and disadvantages of different search way

CodePudding user response:

Select a t1. * from usersetting t1, user t2
Where a t1. Userid=t2. Userid
And t2. The username in (' user1 ', 'user2);

Select * from usersetting t1
Where the exists (select 1 from the user t2 where t1. The userid=t2. The userid and t2. The username in (' user1 ', 'user2));

Two nested will go, feel the user table's primary key role here nothing
  • Related