Insert into 语句用于向表格中插入新的行
---语法
Insert into table_name Values(值1,值2,....)
-指定所要插入数据的列:
Insert into table_name(列1,列2,...) Values (值1,值2,....)
Select into语句从一个表中选取数据,然后把数据插入另一个表中。常用于创建表的备份复件或者用于对于记录进行存档。
-把所有的列插入新表
select *
into new_table_name [IN externaldatabase]
from old_tablename
-只把希望的列插入新表
select column_name(s)
into new_table_name [IN externaldatabase]
from old_tablename
Update
Person表:
UPDATE 表名称 SET 列名称 = 新值 where 列名称 = 某值
LastName | FirstName | Address | City |
---|---|---|---|
Gates | Bill | Xuanwumen 10 | Beijing |
Wilson | Champs-Elysees |
更新某一行中的一个列
我们为lastname 是 “Wilson”的人添加 firstname:
UPDATE Person SET FirstName = 'Fred' WHERE LastName = 'Wilson'
结果:
LastName | FirstName | Address | City |
---|---|---|---|
Gates | Bill | Xuanwuman 10 | Beijing |
Wilson | Fred | Champs-Elysees |
更改某一行中的若干列
我们会修改地址(address),并添加城市名称(city):
UPDATE Person SET Address = 'Zhongshan 23', City = 'Nanjing'
WHERE LastName = 'Wilson'
Delete
DELETE FROM 表名称 WHERE 列名称 = 值
Person:
LastName | FirstName | Address | City |
---|---|---|---|
Gates | Bill | Xuanwumen 10 | Beijing |
Wilson | Fred | Zhongshan 23 | Nanjing |
删除某行
"Fred Wilson"会被删除:
DELETE FROM Person WHERE LastName = 'Wilson'
结果:
LastName | FirstName | Address | City |
---|---|---|---|
Gates | Bill | Xuanwumen 10 | Beijing |
删除所有行
可以在不删除表的情况下删除所有的行。这意味着表的结构,属性和索引都是完整的:
DELETE FROM table_name
或者:
DELETE * FROM table_name