2023-01-10 LightDB创建和删除表.md

LightDB-创建和删除表

  • 创建表
[lightdb@localhost ~]$ ltsql mydb
ltsql (13.8-22.3)
Type "help" for help.

#创建数据表
lightdb@mydb=# CREATE TABLE weather (
    city            varchar(80),
    temp_lo         int,           -- low temperature
    temp_hi         int,           -- high temperature
    prcp            real,          -- precipitation
    date            date
);
lightdb@mydb=# CREATE TABLE COMPANY(
    ID INT PRIMARY KEY     NOT NULL,
    NAME           TEXT    NOT NULL,
    AGE            INT     NOT NULL,
    ADDRESS        CHAR(50),
    SALARY         REAL
);
lightdb@mydb=# CREATE TABLE cities (
    name            varchar(80),
    location        point
);

#列举当前数据库所有表
lightdb@mydb=# \d
                           List of relations
   Schema   |                 Name                 |   Type   |  Owner  
------------+--------------------------------------+----------+---------
 lt_catalog | deps_saved_ddl                       | table    | lightdb
 .......
 public     | cities                               | table    | lightdb 
 public     | company                              | table    | lightdb 
 public     | weather                              | table    | lightdb

#查看表详情
lightdb@mydb=# \d company
                  Table "public.company"
 Column  |     Type      | Collation | Nullable | Default 
---------+---------------+-----------+----------+---------
 id      | integer       |           | not null | 
 name    | text          |           | not null | 
 age     | integer       |           | not null | 
 address | character(50) |           |          | 
 salary  | real          |           |          | 
Indexes:
    "company_pkey" PRIMARY KEY, btree (id)

lightdb@mydb=# \d weather
                      Table "public.weather"
 Column  |         Type          | Collation | Nullable | Default 
---------+-----------------------+-----------+----------+---------
 city    | character varying(80) |           |          | 
 temp_lo | integer               |           |          | 
 temp_hi | integer               |           |          | 
 prcp    | real                  |           |          | 
 date    | date                  |           |          | 
 
lightdb@mydb=# \d cities
                       Table "public.cities"
  Column  |         Type          | Collation | Nullable | Default 
----------+-----------------------+-----------+----------+---------
 name     | character varying(80) |           |          | 
 location | point                 |           |          |
  • 删除表
#删除表
lightdb@mydb=# drop table company;
DROP TABLE
lightdb@mydb=# \d
                               List of relations
   Schema   |                 Name                 |   Type   |  Owner  
------------+--------------------------------------+----------+---------
 lt_catalog | deps_saved_ddl                       | table    | lightdb
 ......
 public     | weather                              | table    | lightdb
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值