插入数据
insert into Customers values ('1000000007','xu','chengdu tianfu 2 street','sichuan chengdu','CA','610000','CHINA','Xu','xu@qq.com');
虽然这种语法简单,但是不安全,这种SQL语句高度依赖表中列的定义次序,应该尽量避免使用。
另外需要注意一点是,values
和value
的区别:插入单行的时候使用VALUES,在插入多行的时候使用VALUE 这样比较快一点。
insert into Customers (cust_id,cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country,cust_contact,cust_email) values ('1000000009','xu','chengdu tianfu 2 street','sichuan chengdu','CA','610000','CHINA','Xu','xu@qq.com');
插入检索出的数据
INSERT SELECT
从一个表复制到另一个表
SELECT INTO
select * into CustCopy from Customers
这句话的意思是,创建一个名为CustCopy的表,并把Customers表中的整个内容复制到新表中。不过MySQL的语法稍有不同:
create table CustCopy as select * from Customers;
更新和删除数据
UPDATE
update Customers set cust_address = 'chengdu tianfu 3 street' where cust_id = '1000000009';
删除某列的值:
update Customers set cust_email = NULL where cust_id = '1000000006';
DELETE
delete from Customers where cust_id = '1000000006';
注意:如果省略了where
,则update
和delete
将被应用到所表中所有的行。
创建和操纵表
创建表
create table
更新表
alter table
alter table Vendors add vend_phone CHAR(20);
删除表
drop table