Home > database >  The data table to update
The data table to update

Time:11-12

There are two tables
Table 1 ID (only), name, city code three fields, hundreds of thousands of rows
Table 2 a city code (only), zip code, area code three fields, hundreds of records

How to create a contains hundreds of thousands of lines to form 3
ID (only), name, city code and city code corresponding to the zip code, city code corresponding to the code

CodePudding user response:

Select a *, b., zip code, b. area code from table 1 a join table 2 b on a. city code=b. city code

CodePudding user response:

I mean, how to create a new table 3. It is best to every day can automatically perform in the middle of the night, to judge whether there is a table 3 first, if in, delete, and then create
Need to write a stored procedure or trigger, such as
Table 1 will not regularly updated
Build entity table does not consider the view of efficiency, is the cause of

CodePudding user response:

Like this: https://www.cnblogs.com/zgqys1980/archive/2006/07/11/447652.html

CodePudding user response:

Look from Lz amount of data and the number of fields, using solid table does not have obvious than league table query or view performance advantages, if feel the current query speed slow, suggested to analyze the execution plan, see whether you need to optimize places, such as adding index or pieces of sorting index and so on

CodePudding user response:

DROP TABLE [dbo] [TABLE]
GO

Select a *, b., zip code, b. area code into table 3 from table 1 a inner join table 2 b on a. city code=b. city code
GO
  • Related