USE db_name

功能描述

USE db_name语句将db_name数据库作为默认(当前)数据库使用,用于后续语句。该数据库保持为默认数据库,直到语段的结尾,或者直到发布一个不同的USE语句。

注意事项

N/A

语法格式

1. USE db_name

参数说明

  • db_name

​ 数据库名。

示例

1. --切换到db1库
2. openGauss=# USE db1;
3. SET
4. openGauss=# CREATE TABLE test(a text);
5. CREATE TABLE
6. openGauss=# INSERT INTO test VALUES('db1');
7. INSERT 0 1

9. --切换到db2库
10. openGauss=# USE db2;
11. SET
12. openGauss=# CREATE TABLE test(a text);
13. CREATE TABLE
14. openGauss=# INSERT INTO test VALUES('db2');
15. INSERT 0 1
16. openGauss=# select a from db1.test;
17. a
18. -----
19. db1
20. (1 row)

22. openGauss=# select a from db2.test;
23. a
24. -----
25. db2
26. (1 row)

28. openGauss=# select a from test;
29. a
30. -----
31. db2
32. (1 row)

34. --切换到db1库
35. openGauss=# USE db1;
36. SET
37. openGauss=# select a from test;
38. a
39. -----
40. db1
41. (1 row)

相关链接

N/A