ITPub博客

首页 > 数据库 > 国内数据库 > OushuDB 基本用法 创建数据库和表

OushuDB 基本用法 创建数据库和表

原创 国内数据库 作者:xiaokissoo 时间:2021-11-23 19:31:53 0 删除 编辑

                       

本节通过使用OushuDB的命令行工具psql来说明如何创建基本数据库对象:database和table。因为OushuDB和PostgreSQL兼容,所以使用OushuDB的方式和使用PostgresSQL的方式基本相同,如果OushuDB的文档有些地方说明不清楚的话,用户也可以通过查阅PostgresSQL的帮助文档来了解更多关于OushuDB的信息。

下面这条命令使用psql连接OushuDB缺省安装的数据库postgres,然后创建一个新的数据库test,并在新的数据库中创建一个表foo。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

changlei:build ChangLei$ psql -d postgres

psql (8.2.15)

Type "help" for help.

postgres=# create database test;  # 创建数据库test

CREATE DATABASE

postgres=# \c test  # 连接进入test数据库

You are now connected to database "test" as user "ChangLei".

test=# create table foo(id int, name varchar);  # 创建表foo

CREATE TABLE

test=# \d  # 显示当前数据库test中所有表

           List of relations

Schema | Name | Type  |  Owner   |   Storage

--------+------+-------+----------+-------------

public | foo  | table | ChangLei | append only

(1 row)

test=# insert into foo values(1, 'hawq'),(2, 'hdfs');

INSERT 0 2

test=# select * from foo; # 从表foo中选择数据

 id | name

----+------

  1 | hawq

  2 | hdfs

(2 rows)

如果想删除表或者数据库的话可以使用drop语句。

test=# drop table foo;

DROP TABLE

test=# \d

No relations found.

test=# drop database test;  # 因为现在在test数据库中,所以不能删除

ERROR:  cannot drop the currently open database

test=# \c postgres  # 首先连接到postgres数据库,然后删除test数据库

You are now connected to database "postgres" as user "ChangLei".

postgres=# drop database test;

DROP DATABASE



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69957629/viewspace-2843753/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-09-03

  • 博文量
    12
  • 访问量
    4997