数据维护与结构

阅读(3170) 标签: 数据维护, 结构,

本章主要展示关于数据维护与结构的代码参考,比如INSERTINSERT FROM SELECT …、DELETE WHERE …、UPDATE WHERE …、CREATE/DROP TABLEALTER TABLEKEYSCONNECT/DISCONNECT/COMMIT/ROLLBACK等。

INSERT

 

A

 

1

=demo.query("select * from SCORES")

 

2

=A1.insert(0,"Class one",20,"PE",100)

追加新记录

3

=A1.insert(5,"Class one",21,"PE",100)

插入新记录

 

INSERT FROM SELECT …

 

A

 

1

=demo.query("select * from SALES")

 

2

=A1.derive()

复制序表

 

DELETE … WHERE …

 

A

 

1

=demo.query("select ORDERID,CLIENT,SELLERID, ORDERDATE,AMOUNT from SALES")

 

3

=A1.delete(A1.select(AMOUNT<10000))

删除满足条件的记录

 

UPDATE … WHERE …

 

A

 

1

=demo.query("select ORDERID,CLIENT,SELLERID, ORDERDATE, AMOUNT from SALES")

 

2

=A1.select(CLIENT:"HL").run(AMOUNT= int(AMOUNT*1.1))

按条件修改数据

 

CREATE/DROP TABLE

 

A

 

1

=create(ProductNo,ProductName,UnitPrice,Quantity)

创建新序表

2

>A1=null

清除序表

 

ALTER TABLE

 

A

 

1

=demo.query("select * from EMPLOYEE")

 

2

=A1.rename(EID:ID)

修改字段名

 

KEYS

 

A

 

1

=demo.query("select * from EMPLOYEE")

 

2

=A1.keys(EID)

设置主键

 

CONNECT/DISCONNECT/COMMIT/ROLLBACK

 

A

B

 

1

=connect@e("demo")

 

建立连接

2

>A1.execute@k(...)

 

 

3

=A1.error()

 

上一条数据库执行的错误信息

4

if A3==0

>A1.commit()

无错则提交

5

else

>A1.rollback()

有错则回滚

6

>A1.close()

 

关闭连接