回覆列表
  • 1 # DIY分享秀

    SELECT

    t.TABLE_NAME,

    t.CONSTRAINT_TYPE,

    c.COLUMN_NAME,

    c.ORDINAL_POSITION

    FROM

    INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS t,

    INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS c

    WHERE

    t.TABLE_NAME = c.TABLE_NAME

    AND t.TABLE_SCHEMA = "test"

    AND t.CONSTRAINT_TYPE = "PRIMARY KEY";

    這是表示查詢表有主鍵,改一下就知道那些表不含主鍵了。

  • 2 # 牙醬

    獲取資料庫中除系統庫之外所有無主鍵的表sql如下:

    SELECT

    table_schema,

    table_name

    FROM

    information_schema. TABLES

    WHERE

    (table_schema, table_name) NOT IN (

    SELECT DISTINCT

    table_schema, table_name

    FROM

    information_schema. COLUMNS

    WHERE

    COLUMN_KEY = "PRI"

    )

    AND table_schema NOT IN (

    "sys",

    "mysql",

    "information_schema",

    "performance_schema"

    );

  • 中秋節和大豐收的關聯?
  • 假如秦朝未統一六國,後來的亞洲很有可能會出現什麼格局?