每日一练:openGauss数据库在线实训课程 ## 第二天作业

1.创建一个表products

CREATE TABLE products
( product_id integer,   
  product_name char(30),    
  category char(30)
) ;

2.向表中插入数据,采用一次插入一条和多条记录的方式

INSERT INTO products (product_id, product_name, category) VALUES (1502, 'olympus camera', 'electrncs');

INSERT INTO products (product_id, product_name, category) VALUES    
(1502, 'olympus camera', 'electrncs'),    
(1601, 'lamaze','toys'),    
(1700, 'wait interface', 'Books'),
(1666, 'harry potter', 'toys');

3.获取表中一条记录、三条记录和所有记录

\dt products
select * from products limit 1;
select * from products limit 3;
select * from products;

4.将满足product_id > 1600的记录的product_id更新为product_id – 1000,并查看products中所有记录是否更新成功

update customer_t set c_customer_sk = c_customer_sk * 2 where c_customer_sk < 5000;
select * from products;
update products set product_id = product_id - 1000 where product_id > 1600;
select * from products;

5.删除category为toys的所有记录,并查看products中数据是否删除成功

select * from products;
delete from products where category='toys';
select * from products;

6.删除products中所有数据,并查看数据是否删除成功

delete from products;
select * from products;

7.删除表products

drop products;

truncate table products;

猜你喜欢

转载自blog.csdn.net/hezuijiudexiaobai/article/details/121727110