文档主页
适用于 VS Code 的 MySQL Shell


适用于 VS Code 的 MySQL Shell  /  JavaScript  /  数据库笔记本:创建和删除视图

正式发布前:2024-07-17

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

数据库笔记本:创建一个视图并使用 LIKE 显示表

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

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

输出为

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

  }
]

数据库笔记本:删除一个视图并使用 LIKE 显示表

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

输出为

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