When you apply DB2, you may encounter some seemingly simple problems, especially for beginners, I have a simple
Summed up, released to everyone, I hope that we can help, but also welcome everyone to discuss together, common development and common progress!
The following are mainly based on db27.x. The following characters are lowercase.
This article for DB2 Master is not to see.
All characters are lowercase.
91. How do I create a DB2 summary table?
DB2 's summary table functionality is similar to the materialized view of Oracle!
The syntax is:
Createsummarytabletable_nameas (fullselect) ...
For example:
Define a summary table that can be refreshed:
Createsummarytabletable_nameas (select*fromtable_name1wherecol1= AAA)
Datainitiallydeferredrefreshdeferred
Where datainitiallydeferred stipulates that data cannot be inserted into a table as part of a createtable statement.
Refreshdeferred specify that the data in the table can be refreshed at any time when the refreshtable statement is used!
92. How do I refresh the summary table?
Refreshtablesum_table
Where sum_table is a summary table.
93. How do I modify the summary table?
Altertablesum_table ...
94. How do I create a temporary table?
Grammar:
Declareglobaltemporarytabletable_name
As (Fullselect) definitiononly
Excludingidentitycolumnattributes
Oncommitdeleterows
Notlogged
The first line stipulates the name of the temporary table.
The second row defines the columns of the temporary table.
The third line stipulates that the identity column is not replicated from the source result table definition.
Line four stipulates that if you do not open the Withgold cursor, all rows of the table will be deleted.
Line five provides no record of changes to the table.
For example:
Declareglobaltemporarytabledec_bsempms
As (SELECT*FROMBSEMPMS) definitiononly
Excludingidentitycolumnattributes
Oncommitdeleterows
Notlogged
95. Management of views?
How to create a view:
Createviewview_nameasselect*fromtable_namewhere ...
To delete a view:
Dropviewview_name
96. How do I know what the view definition is?
Select*fromsyscat. Text column in the views.
97. How do I create an alias?
Createaliasalias_nameforpro_name
The pro_name in the back can be table,view,alias,nickname and so on.
98. How do I create a sequence?
For example:
Createsequencesequence_name
Startwithstart_number
INCREMENTBYVALUE1
Nomaxvalue
Nocycle
Cachemaximumnumberofsequencevalues
The first line prescribes the name of the sequence.
The second line sets the starting value of the sequence.
The third line sets the range of the new each time.
There is no maximum numerical limit for the four-line rule.
Line five provides maximum numerical limit.
99. How do I change the sequence?
Altersequencesequence_name ...
Parameters that can be modified
Startwith's Start_number
Increment's VALUE1
Number of Nomaxvalue
Nocycle Property
Maximumnumberofsequencevalues Maximum Value