用于 VS 代码的 MySQL Shell GUI / MySQL Shell  / 第 9 章打字稿  /  9.3 数据库笔记本:创建和删除视图

全面上市前:2022-11-17

9.3 数据库笔记本:创建和删除视图

DB Notebook:创建视图并使用 LIKE 显示表

runSql ("CREATE VIEW AlbertaAddresses AS SELECT * FROM sakila.address WHERE district = 'Alberta'");

//check TABLES for successful CREATE VIEW
runSql ("SHOW TABLES LIKE 'AlbertaAddresses' ",  
(ResultSetData) => {
    print(ResultSetData);
  }
);

输出是:

[
  {
      "Tables_in_sakila (AlbertaAddresses)": "albertaaddresses"

  }
]

DB Notebook:删除视图并使用 LIKE 显示表

runSql ("DROP VIEW IF EXISTS albertaaddresses");
//check TABLES for successful DROP VIEW
runSql ("SHOW TABLES LIKE 'A%' ",  
(IResultSetData) => {
    print(IResultSetData);
  }
);

输出是:

[
  {
      "Tables_in_sakila (A%)": "actor"
  },
  {
      "Tables_in_sakila (A%)": "actor_info"
  },
  {  
      "Tables_in_sakila (A%)": "地址"
  }
]