-1

I'm new to mysql, my question is that is this correct?

CREATE TABLE ... (
    /* some definition ommitted. */
    About varchar(300) NOT NULL DEFAULT '...',
    CHECK(About LIKE 'ABOUT: %, DATE: %')
);

By searching, all results show LIKE within SELECT, so is it syntactically correct to be used in CHECK?

NeoZoom.lua
  • 2,269
  • 4
  • 30
  • 64

1 Answers1

0

Yes, syntactically that is OK.

But two things:

  1. Be aware that below version 8.0.16, MySQL does accept check constraints in a table DDL but it doesn't enforce the check constraints. so it's like they weren't there at all.

    You should check if that's applicable to your version.

  2. And more importantly, you seem to make a big mistake there, violating the first normal form.

    It seems like there are two attributes here, some sort of textual description and some point in time. That should really be two different columns.

    Don't put their values together in one big text column!

    Otherwise I'll guarantee you a lot of headaches in the future:

    • Every time you want to query one of the two attributes you first need to parse the entire text.
    • You cannot create any useful indexes that help boost performance.
    • Updating one attribute means changing the whole text but in the right spot instead of just the attribute itself.
    • And so on and so on...
sticky bit
  • 36,626
  • 12
  • 31
  • 42