1、select * into destTbl from srcTbl。
2、insert into destTbl(fld1, fld2) select fld1, 5 from srcTbl。
以上两句都是将 srcTbl 的数据插入到 destTbl,但两句又有区别的:
第一句(select into from)要求目标表(destTbl)不存在,因为在插入时会自动创建。
第二句(insert into select from)要求目标表(destTbl)存在,由于目标表已经存在,所以我们除了插入源表(srcTbl)的字段外,还可以插入常量。
拓展资料:结构化查询语言(Structured Query Language)简称SQL,结构化查询语言是一种数据库查询和程序设计语言,用于存取数据以及查询、更新和管理关系数据库系统。sql 语句就是对数据库进行 *** 作的一种语言。
常见语句:
1、更新:update table1 set field1=value1 where 范围。
2、查找:select * from table1 where field1 like ’%value1%’ (所有包含‘value1’这个模式的字符串)。
3、排序:select * from table1 order by field1,field2 [desc]。
4、求和:select sum(field1) as sumvalue from table1。
5、平均:select avg(field1) as avgvalue from table1。
6、最大:select max(field1) as maxvalue from table1。
7、最小:select min(field1) as minvalue from table1[searator]。
在数据库中添加一行的SQL语句写法的步骤如下:
我们需要准备的材料分别是:电脑、sql查询器。
1、首先,打开sql查询器,连接上相应的数据库表,以stu2表添加一行数据为例。
2、点击“查询”按钮,输入:insert into stu2(first_name, last_name, age, sex) values('赵', '六', 16, 1)。
3、点击“运行”按钮,此时提示“受影响的行:1”。
4、重现打开stu2表,发现数据添加了一行。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)