This question follows up the following previous question. is it possible to make a field in Mysql table to to have length max=700, to be unicode (3 bytes) and to be unique?
I have a table MyText
which have ID
column, text
column & many other columns
Id - text - type ..& other fileds 1 - this is my text 2 - xxxx
I want the text
column support unicode with max length can hold 700 Unicode characters. I can't set Unique (text)
because MYSQL only supports 765 bytes max length for unique column while Unicode takes 3 bytes so I need 2100 bytes (700*3) unique column.
So, the solution is to crate a trigger that prevents the user to insert the duplicate. For example, if user inserts "THIS is My Text
" (We won't care case sensitive) into MyText
table, then Mysql will abort completely ALL Queries that contain that Inserting Statement and will generate an SQLException
to prevent the system to do other query.
Ok, suppose you have to run a series of sql statements in your Java code
insert into MyText('THIS is My Text',1);
insert into OtherTable ('some text');
update othetTable...
Then when the system doing the insert into MyText('THIS is My Text',1);
, it should stop doing other queries below it.
Also, some people suggests to do the prefix index
to help Nysql to do the select
quicker, but I am not sure it is too necessary since I got ID colum which was indexed.
Note: MYSQL 5.027 is 2006 version which is pretty old, but I love it
SO how to create trigger that meets my requirement or how to fix my problem?