一、理论:
1.触发器不能使用采用call的动态sql,不能直接返回数据到客户端
2.不能在触发器中使用开始或者结束事务的语句
3.触发器只能在支持事务的表中回滚
二、实践:
mysql> use test1; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> create table film_text( -> film_id int(11), -> title varchar(20), -> description varchar(180) -> ) engine = innodb charset = utf8 ; Query OK, 0 rows affected (0.05 sec) mysql> create table film( -> film_id int(11), -> title varchar(20), -> description varchar(180) -> ) engine = innodb charset = utf8 ; Query OK, 0 rows affected (0.02 sec) mysql> CREATE TABLE `tri_demo` ( -> `id` int(11) auto_increment not null primary key, -> `note` varchar(50) DEFAULT NULL -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ; Query OK, 0 rows affected (0.03 sec) mysql> create trigger ins_film_bef -> before insert on film for each row begin -> insert into tri_demo(note) values ('before insert'); -> end; -> $$ Query OK, 0 rows affected (0.02 sec) mysql> create trigger ins_film_aft -> after insert on film for each row begin -> insert into film_text(title) values ('after insert'); -> end; -> $$ Query OK, 0 rows affected (0.02 sec) mysql> create trigger upd_film_bef -> before update on film for each row begin -> insert into tri_demo(note) values ('before update'); -> end; -> $$ Query OK, 0 rows affected (0.00 sec) mysql> create trigger upd_film_aft -> after update on film for each row begin -> insert into tri_demo(note) values ('after update'); -> end; -> $$ Query OK, 0 rows affected (0.02 sec) mysql> delimiter ; mysql> insert into film values ( 1,'film_name','film_description'); Query OK, 1 row affected (0.00 sec) mysql> select * from film; +---------+-----------+------------------+ | film_id | title | description | +---------+-----------+------------------+ | 1 | film_name | film_description | +---------+-----------+------------------+ mysql> select * from tri_demo; +----+---------------+ | id | note | +----+---------------+ | 1 | before insert | +----+---------------+ mysql> update film set title='film_update' where film_id = 1; Query OK, 1 row affected, 1 warning (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> select * from film; +---------+--------------------+--------------------------+ | film_id | title | description | +---------+--------------------+--------------------------+ | 1 | film_update | film_description | +---------+--------------------+--------------------------+ 1 rows in set (0.00 sec) mysql> select * from tri_demo; +----+---------------+ | id | note | +----+---------------+ | 1 | before insert | | 2 | before update | | 3 | after update | +----+---------------+ 3 rows in set (0.00 sec) mysql> show triggers \G; *************************** 1. row *************************** Trigger: ins_film_bef Event: INSERT Table: film Statement: begin insert into tri_demo(note) values ('before insert'); end Timing: BEFORE Created: NULL sql_mode: Definer: root@localhost character_set_client: utf8 collation_connection: utf8_general_ci Database Collation: utf8_general_ci *************************** 2. row *************************** Trigger: ins_film_aft Event: INSERT Table: film Statement: begin insert into film_text(title) values ('after insert'); end Timing: AFTER Created: NULL sql_mode: Definer: root@localhost character_set_client: utf8 collation_connection: utf8_general_ci Database Collation: utf8_general_ci *************************** 3. row *************************** Trigger: upd_film_bef Event: UPDATE Table: film Statement: begin insert into tri_demo(note) values ('before update'); end Timing: BEFORE Created: NULL sql_mode: Definer: root@localhost character_set_client: utf8 collation_connection: utf8_general_ci Database Collation: utf8_general_ci *************************** 4. row *************************** Trigger: upd_film_aft Event: UPDATE Table: film Statement: begin insert into tri_demo(note) values ('after update'); end Timing: AFTER Created: NULL sql_mode: Definer: root@localhost character_set_client: utf8 collation_connection: utf8_general_ci Database Collation: utf8_general_ci 4 rows in set (0.01 sec)

MySQLユーザーを追加する方法を習得することは、データベース管理者と開発者にとって重要です。これは、データベースのセキュリティとアクセス制御を保証するためです。 1)CreateUserコマンドを使用して新しいユーザーを作成し、2)付与コマンドを介してアクセス許可を割り当て、3)FlushPrivilegesを使用してアクセス許可を有効にすることを確認します。

choosecharforfixed-lengthdata、varcharforvariable-lengthdata、andtextforlargetextfields.1)chariseffienceforconsistent-lengthdatalikecodes.2)varcharsuitsvariaible-lengthdatalikenames、balancingflexibilityandperformance.3)Textisidealforforforforforforforforforforforidex

MySQLの文字列データ型とインデックスを処理するためのベストプラクティスには、次のものが含まれます。1)固定長のchar、可変長さのvarchar、大規模なテキストのテキストなどの適切な文字列タイプを選択します。 2)インデックス作成に慎重になり、インデックスを避け、一般的なクエリのインデックスを作成します。 3)プレフィックスインデックスとフルテキストインデックスを使用して、長い文字列検索を最適化します。 4)インデックスを定期的に監視および最適化して、インデックスを小さく効率的に保つ。これらの方法により、読み取りと書き込みのパフォーマンスをバランスさせ、データベースの効率を改善できます。

toaddauserremotelytomysql、フォローステープ:1)connecttomysqlasroot、2)createanewuserwithremoteaccess、3)grantniverayprivileges、and4)flushprivileges.

tostorestringseffiedlyinmysql、choosetherightdatatypebasedonyourneadss:1)usecharforfixed-lengthstringslikecountrycodes.2)usevarforvariable-lengthstringslikenames.3)usetextfor forlong-formtextcontent.4)useblobforborikedalikeimages

MySQLのBLOBおよびテキストデータ型を選択する場合、BLOBはバイナリデータの保存に適しており、テキストはテキストデータの保存に適しています。 1)BLOBは、写真やオーディオなどのバイナリデータに適しています。2)テキストは、記事やコメントなどのテキストデータに適しています。選択するときは、データプロパティとパフォーマンスの最適化を考慮する必要があります。

いいえ、Youは、usotherootuserinmysqlforyourproduct.instead、createpificusers withlimitedprivilegestoenhancesecurityandperformance:1)createanewuserwithastrongpassword、2)grantonlynlyneversearpermissionStothisuser、3)正規環境筋肉筋周辺の環境

mysqlstringdatatypesshouldbechosenbadedatacharacteristicsandusecases:1)usecharforfixed-lengthstringslikecountrycodes.2)usevarforvariable-lengthstringslikenames.3)usebinaryorvarniaryforbinarydatalikecryptograpograpogrationckeys.4)使用


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

Safe Exam Browser
Safe Exam Browser は、オンライン試験を安全に受験するための安全なブラウザ環境です。このソフトウェアは、あらゆるコンピュータを安全なワークステーションに変えます。あらゆるユーティリティへのアクセスを制御し、学生が無許可のリソースを使用するのを防ぎます。

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

SublimeText3 中国語版
中国語版、とても使いやすい

WebStorm Mac版
便利なJavaScript開発ツール

Dreamweaver Mac版
ビジュアル Web 開発ツール
