- 更新表中的特定行;
- 更新表中的所有行;
在使用UPDATE前,应该保证自己有足够的安全权限。
update Customers set cust_email = 'kim@thetoystore.com' where cust_id = '1000000005';
//更新多列
update Customers set cust_contact = 'Sam Roberts', cust_email = 'sam@thetoystore.com' where cust_id = '1000000006';
要删除某个列的值,可设置它为NULL(假如表定义运行NULL值)。
删除数据
删除特定的行,删除所有行
在使用delete时,要有足够的安全权限。
delete不需要列名或通配符。delete删除整行而不是删除列。要删除列,请使用update语句
delete删除表的内容而不是表
-
插入完整的行
-
插入行的一部分
-
插入某些查询的结果
-
插入完整的行
insert into Customers values('1000000006','TOY LAND','123 ANY STREET','NEW YORK','NY','11111','USA','null','null');
以上语法简单,但是不安全,高度依赖于其容易获得的次序信息
可以使用以下语法
insert into Customers (cust_id,cust_contact,cust_email,cust_name,cust_address,cust_city,cust_state,cust_zip) values('1000000008','null','null','TOY LAND','123 ANY STREET','NEW YORK','NY','11111');
省略列:该列定义为允许null值(无值或空值)
2. 插入部分行
3. 插入检索出的数据
insert into Customers(cust_id,cust_contact,cust_email,cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country) select cust_id,cust_contact,cust_email,cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country
from CustNew;
insert select 中select语句可以包含where子句,以过滤插入数据。
4. 从一个表复制到另一个表
insert select 将数据添加到一个已经存在的表不同,select into 将复制到一个新表
select* into CustCopy from Customers;