文档首页
MySQL Shell for VS Code


MySQL Shell for VS Code  /  TypeScript  /  数据库笔记本:创建和删除视图

预发布:2024-07-17

9.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' ",  
(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%' ",  
(IResultSetData) => {
    print(IResultSetData);
  }
);

输出是

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