1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > SQL必知必会学习笔记11-Kane

SQL必知必会学习笔记11-Kane

时间:2021-07-25 10:10:53

相关推荐

SQL必知必会学习笔记11-Kane

十一.数据插入

数据插入

插入完整行

insert into customersvalues('1000000006','toy land','123 Any street','new york','NY','USA',NULLNULL);

但是这样必须让插入的数据保持和表中每行数据完全一样的顺序,很不安全

更安全的做法是限定每个数据表示的列

insert into customers(cust_id,cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country,cust_contact,cust_email)values('1000000006','toy land','123 Any street','new york','NY','USA',NULLNULL);

只插入部分行而把其他的留着也是可以的

也可以把一个表中检索出的数据插入另一个表中:

insert into customers(cust_id,cust_name,cust_address,cust_city,cust_state,cust_zip,cust_country)select cust_id,cust_name,cust_address,cust_city,cust_state,cust_zip,cust_countryfrom Custnew;#但是进行这种操作的时候要注意,主键值(cust_id不可以重复,否则插入会失败)

将一个表复制到另一个表

select*into custcopyfrom customers;

creat table custcopy asslect * from customers;#适用于mySQL,Oracle,PostgreSQL,SQLite等

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。