当前位置:网站首页>Dameng database_ Trigger, view, materialized view, sequence, synonym, auto increment, external link and other basic operations
Dameng database_ Trigger, view, materialized view, sequence, synonym, auto increment, external link and other basic operations
2022-07-24 06:11:00 【ls2best】
trigger
Create trigger
SQL> create or replace trigger ss before delete on aa for each row begin print 11;endReset trigger
SQL> alter triger sysdba.ss compile;Delete trigger
SQL> drop trigger ss;Trigger classification
Trigger is a basic component of application segmentation technology , It moves transaction rules from the application code to the database , This ensures that these transaction rules are strengthened and their performance improved .
DM Three types of triggers are provided :
1. Table level triggers : Trigger based on the data in the table ;
2. Event trigger : Trigger based on specific system events ;
3. Time trigger : Trigger based on time .
Triggers are special stored procedures attached to a specific table or view , It's somewhere DML Automatically execute under the excitation of operation . When creating a trigger, you should carefully consider its relevant information . say concretely , The following aspects should be considered :
1. Which table should trigger be built in / Above the view ;
2. What kind of trigger should be used DML The operation responds ;
3. The trigger is in the specified DML Fire before or after the operation ;
4. Yes, every time DML Respond once , Or to receive DML Each row of data affected by the operation responds once .
View
Create view
SQL> create view w as select * from ss;Compile view
SQL> alter view sysdba.w compile;View view
SQL> SELECT * FROM SYS.SYSOBJECTS a, SYS.SYSTEXTS b WHERE a.ID = b.ID AND NAME=‘w’ ;Delete view
SQL> drop view if exists sysdba.w cascade;There are two ways to delete views :RESTRICT/CASCADE The way . among RESTRICT Is the default value .
When setting dm.ini Parameters in DROP_CASCADE_VIEW The value is 1 when , If there are other views built on this view , You have to use CASCADE Parameter can delete all views established on this view , Otherwise, the operation of deleting the view will not succeed ; When setting dm.ini Parameters in DROP_CASCADE_VIEW The value is 0 when ,RESTRICT and CASCADE All ways will succeed , And only the current view will be deleted , The view established on this view will not be deleted .
Materialized view
Parameters
- < Schema name > Indicate which mode the created view belongs to , The default is the current mode ;
- < Materialized view name > Indicate the name of the materialized view created ;
- < Name > Indicates the name of the column in the materialized view created ;
- [BUILD IMMEDIATE|BUILD DEFERRED] To specify BUILD IMMEDIATE Fill data immediately , The default is immediate fill ;BUILD DEFERRED Fill for delay , Using this method requires that the first refresh must be COMPLETE Full refresh .
- < Subquery expression > Identify the rows and columns of the table on which the materialized view is based . Its syntax follows SELECT The grammatical rules of sentences ;
- < Table joins > Please refer to the table connection query section in Chapter 4 ;
- Define ORDER BY Clause is only used when creating materialized views , thereafter ORDER BY Be ignored ;
- Refresh mode
FAST: Perform incremental refresh according to the data change record on the related table . Ordinary DML The records generated by the operation exist in the materialized view log . Use FAST Before refreshing , You must first create a materialized view log .
COMPLETE: Completely refresh by executing the definition script of the materialized view .
FORCE: The default option . Use fast refresh when fast refresh is available , Otherwise, use full refresh .
- Refresh time
ON COMMIT: Perform a quick refresh when submitting views on related tables . Refresh is performed by asynchronous threads , therefore COMMIT After execution, you may need to wait for a period of time before materialized view data is up-to-date .
constraint : Objects with object types are not supported ; Including remote tables is not supported .
START WITH … NEXT:START WITH Used to specify the time when the materialized view is refreshed for the first time ,NEXT Specify the interval of automatic refresh ; If omitted START WITH Then the first refresh time is the current time plus NEXT Specified interval ; If specified START WITH Omit NEXT The materialized view will only be refreshed once ; If neither is specified, the materialized view will not be refreshed automatically .
ON DEMAND: By the user REFRESH Syntax to refresh manually . If you specify START WITH and NEXT Clause, there is no need to specify ON DEMAND.
NEVER REFRESH: Materialized views are never refreshed . Can pass ALTER MATERALIZED VIEW < Materialized view name > FRESH Make changes .
- Refresh options
WITH PRIMARY KEY: The default option .
It can only be based on a single table ;
Must contain PRIMARY KEY constraint , The selection column must directly contain all PRIMARY KEY(UPPER(col_name) The form of is unacceptable );
Cannot contain object type .
WITH ROWID:
It can only be based on a single table ;
Cannot contain object type ;
If you use WITH ROWID While using fast refresh , You have to ROWID extracted , Together with other column names , Display as an alias .
- QUERY REWRITE Options
ENABLE: Allow materialized views to be used for query rewriting .
DISABLE: Materialized views are forbidden for query rewriting .
at present DM8 Only syntax supports query rewrite options , The actual function is not realized .
- datetime_expr Only date constant expressions ,SYSDATE[+< Numerical constants >] Or date interval ;
- If the materialized view contains large columns , You need to manually specify STORAGE(USING LONG ROW) Storage mode .
Materialized view creation
SQL> create MATERIALIZED view sysdba.qq BUILD IMMEDIATE REFRESH WITH ROWID START WITH SYSDATE NEXT SYSDATE+3 AS select id,name,uname from utest where iname=’123’;
Create materialized views qq Yes iname=’123’ Conditions ,id,name,uname
basis ROWID Refresh and the refresh interval is 3 Update the materialized view Materialized view delete
SQL> DROP MATERIALIZED VIEW if exists sysdba.qq;Materialized view modification
SQL> ALTER MATERIALIZED VIEW SYSDBA.qq REFRESH COMPLETE;
Change to completely delete Materialized view update
SQL> REFRESH MATERIALIZED VIEW sysdba.qq force;Materialized log creation
SQL> CREATE MATERIALIZED VIEW LOG ON sysdba.qq WITH ROWID(id,name ,name2) PURGE START WITH SYSDATE + 5 REPEAT INTERVAL ‘1’ DAY;Materialized view log deletion
SQL> DROP MATERIALIZED VIEW LOG ON sysdba.qq;Sequence
Concept
Sequence (sequence) yes DM One of the database entities in the database . By using sequences , Multiple users can generate and use a set of ordered integer values that are not repeated . For example, you can use sequences to automatically generate primary key values . Sequences simplify programming by providing a sequence table of unique values .
When a sequence is called by a query for the first time , It will return a predetermined value , The predetermined value is the initial value specified when creating the sequence . By default , For ascending sequences , The default initial value of the sequence is the minimum value of the sequence , For descending sequences , The default initial value is the maximum value of the sequence . You can specify the maximum value that the sequence can generate , By default , The maximum value of descending sequence defaults to -1, The maximum value of ascending sequence is 263-1; You can also specify the minimum value that the sequence can generate , By default , The minimum value of ascending sequence defaults to 1, The minimum value of descending sequence is -263. The maximum and minimum values of the sequence can be specified as longint(4 Bytes ) The largest and smallest signed integers that can be represented .
In every subsequent query , The sequence will produce a value that increases by its specified increment . The increment can be any positive integer or negative integer , But not for 0. If this value is negative , The sequence is descending , If this value is positive , The sequence is ascending . By default , The default for adding is 1.
Once the sequence is generated , The user can be in SQL The following pseudo columns are used in the statement to access the value of the sequence :
- CURRVAL Returns the current sequence value ;
- NEXTVAL If it is an ascending sequence , Increase the sequence value and return the increased value ; If it is a descending sequence , Reduce the sequence value and return the reduced value .
Sequences can be circular , When the value of the sequence reaches the maximum / When the minimum value , The sequence will start from the minimum / Maximum count . When using a sequence , There is no guarantee that a series of continuously increasing values will be generated . for example , If you query the next value of a sequence for insert Use , Then the query is the only session that can use this sequence value . If the transaction fails to be committed , Then the sequence value is not inserted into the table , After the insert The subsequent values of this sequence will continue to be used .
Sequences are of great use in the use of numbers , If you want to create a column for the table to represent the number , If the order number , This allows you to use sequences , Incrementally generate , Users do not need special management , This brings great convenience to users . If the user needs the interval number , When creating a sequence, specify INCREMENT, You can generate the number required by the user .
Use NEXTVAL: Visit a sequence for the first time , In reference to sequence.CURRVAL You must quote before sequence.NEXTVAL. For the first time NEXTVAL, Return the initial value of the sequence . Every subsequent reference NEXTVAL, Use defined step Increase the sequence value and return the value after the new addition of the sequence .
Use CURRVAL: Any right CURRVAL Returns the current value of the specified sequence , This value is the last time for NEXTVAL The value returned by the reference of . use NEXTVAL After generating a new value , Can continue to use CURRVAL Access this value , Whether another user adds this sequence or not .
Create sequence
SQL> CREATE SEQUENCE SEQ INCREMENT BY 10;Modify the sequence
SQL> ALTER SEQUENCE SEQ1 INCREMENT BY 1;Delete sequence
SQL> DROP SEQUENCE IF EXISTS SYSDBA.SEQ;step
- About the modification of step size , There are two situations :a) If it doesn't work before modification NEXTVAL Access sequence , Modify the sequence step value directly after creating the sequence , Then the current value of the sequence is the starting value plus the difference between the new step length value and the old step length value ;b) If you use NEXTVAL Accessed sequence , Then modify the sequence step value , Then visit the sequence again The current value of the column is the last value of the sequence plus the new step length .
- Default sequence options : If an option is not indicated in the modification sequence statement, the default is the option value before modification . It is not allowed not to specify any options 、 Do not repeat or conflict with the option description ;
- The starting value of the sequence cannot be modified ;
- The minimum value of the modified sequence cannot be greater than the starting value 、 The maximum value cannot be less than the starting value ;
- The absolute value of the step size of the modified sequence must be less than MAXVALUE And MINVALUE Difference ;
- The current value of the sequence cannot be greater than the maximum value , It can't be less than the minimum ;
- After modifying the current value of the sequence , Need to use NEXTVAL Get the current value of the modified sequence .
A synonym for
Create synonyms
SQL> CREATE OR REPLACE SYNONYM sysdba.www FOR sysdba.aa
SQL> SELECT COUNT(*) FROM sysdba.www;Delete synonyms
SQL> DROP SYNONYM sysdba.www;On the column
Create autoincrement Columns
SET IDENTITY_INSERT attribute , Set whether explicit values are allowed to be inserted into the autoincrement column of the table .ON yes ,OFF no .
Grammar format
SQL> SET IDENTITY_INSERT [< Schema name >.]< Table name > ON WITH REPLACE NULL;
SQL> SET IDENTITY_INSERT [< Schema name >.]< Table name > OFF;
SQL> SET IDENTITY_INSERT PERSON.PERSON_TYPE ON;
SQL> INSERT INTO SYSDBA.WWW(ID,NAME)VALUES(5,‘SD’);When it comes to off Cannot specify auto increment column value
SQL> SET IDENTITY_INSERT SYSDBA.WWW ON WITH REPLACE NULL;
SQL> INSERT INTO SYSDBA.WWW(ID,NAME) VALUES(NULL,‘DS’);When set null Replace self increment . Create a self incrementing column in the table . This attribute is related to CREATE TABLE Statement together , A table can only have one auto increment column .
SQL> CREATE TABLE www(id int IDENTITY(1,1),name varchar (20));External links
Instructions
1. To create to DM External links to the database , You must first configure dmmal.ini, Can be used LINK.DM The connection string of has two formats :
INSTANCE_NAME: Directly use the instance name of the remote library ( The instance name must be configured to dmmal.ini in );
<IP Address >/< Port number >: The port number is DM Externally linked server dmmal.ini The configuration of the MAL_PORT Port number .
dmmal.ini The value of each configuration item 、 The order before and after , Must be completely consistent .dmmal.ini You need to pay attention to the detailed configuration of... At the same time dm.ini Medium MAL_INI The parameter is set to 1 In order to open MAL System .
2. To create to ORACLE External links to , You can use the configured network service name <tsn_name>; If not configured tsn_name, You can use connection descriptors or <IP Address >/< service name > As a connection string .
3. To create to ORACLE External links to , It needs to be installed on the current machine ORACLE Of OCI Interface , And we need to make sure that OCI Interface and DM Version in 32 position /64 The bits are consistent .
4. adopt LINK Changes made to the remote server , By the user on the local server through commit or rollback Commit or roll back .
5. Only ordinary users are supported , I won't support it SSL and Kerberos authentication .
6.DM8 Connecting to its own instance is not supported LINK.
7. Support in CREATE SCHEMA in CREATE LINK, But not supported CREATE PUBLIC LINK.
8. Only DBA And have CREATE LINK Users with permissions can create external links .
9. When DBLINK When a multi machine system is linked and multiple servers are specified , If the connected server fails to provide services due to unexpected conditions such as downtime ,DBLINK According to the set < Connection type >, Select the appropriate server from the remaining servers to connect .
( One ) Create by network service name
SQL> CREATE LINK LINK1 CONNECT 'ORACLE'WITH USER01 IDENTIFIED BY USER01 USING 'ORCL';( Two ) Create through connection descriptor
SQL> CREATE OR REPLACE LINK LINK1 CONNECT 'ORACLE' WITH USER01 IDENTIFIED BY USER01 USING '(DESCRIPTION =(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.0.225)(PORT = 1521)))(CONNECT_DATA = (SERVICE_NAME = orcl) ))';( 3、 ... and ) adopt <IP Address >/< service name > establish
SQL> CREATE LINKLINK1 CONNECT 'ORACLE' WITHUSER01 IDENTIFIED BY USER01 USING '192.168.0.225/orcl';Delete external links
DROP LINK LINK1;Dameng community address :https://eco.dameng.com
边栏推荐
- AD1256
- Use QT to connect to MySQL and create table numbers, write data, and delete data
- Common methods of array
- MySql下载,及安装环境设置
- JVM system learning
- Thymeleaf quick start learning
- Iotp2pgate two IOT devices point-to-point communication fast implementation scheme
- MySql与Qt连接、将数据输出到QT的窗口tableWidget详细过程。
- Foundation of JUC concurrent programming (7) -- multithread lock
- Draw contour cv2.findcontours function and parameter interpretation
猜你喜欢

MySql与Qt连接、将数据输出到QT的窗口tableWidget详细过程。

使用Keras实现CNN+BiLSTM+Attention的多维(多变量)时间序列预测

Use QT to connect to MySQL and create table numbers, write data, and delete data

Yolov5 learning summary (continuously updated)
![[FatFs] migrate FatFs manually and transfer SRAM virtual USB flash disk](/img/fb/5f3d17f1f3d6e4979ece5126e2925e.png)
[FatFs] migrate FatFs manually and transfer SRAM virtual USB flash disk

Foundation of JUC concurrent programming (6) -- lock lock

Sequential stack C language stack entry and exit traversal

顺序栈 C语言 进栈 出栈 遍历
![[activiti] process variables](/img/5e/34077833f6eb997e64f186d4773e89.png)
[activiti] process variables

Deepsort summary
随机推荐
day1-jvm+leetcode
How to download videos on the web
[principles of database system] Chapter 4 advanced database model: Unified Modeling Language UML, object definition language ODL
碰壁记录(持续更新)
用指针访问二维数组
Demo of UDP communication applied to various environments
AD1256
使用Keras实现 基于注意力机制(Attention)的 LSTM 时间序列预测
String methods and instances
【数据库系统原理】第四章 高级数据库模型:统一建模语言UML、对象定义语言ODL
JDBC advanced -- learning from Shang Silicon Valley (DAO)
Conversion of world coordinate system, camera coordinate system and image coordinate system
MySQL基础---约束
HoloLens 2 中文开发文档 MRTK v2
Search of two-dimensional array of "sword finger offer" C language version
HAL_Delay()延时误差约1ms的问题
day4-jvm
Thymeleaf快速入门学习
顺序栈 C语言 进栈 出栈 遍历
HoloLens2开发:使用MRTK并且模拟眼动追踪