2个表:
a1
a b c d
1 2 3 4
11 22 33 44a2
a b c
1 2 3
11 22 33
由于这里没有数据库,所以我想问一下:
1,如果我在a1中插入2个数据,是不是
insert into a1(a,b,c,d)
values('aa','bb','cc','dd')
insert into a1(a,b,c,d)
values('aaa','bbb','ccb','ddd')
这样要执行2次,请问直接写一句insert into 是否可以。
2,请问我要删除表a1中的第一行数据变为
a b c d
11 22 33 44
delete from a1 where a1.a=1
是否正确?
3,如果要修改a1中字段b的数据使的b的第2行变成222
a b c d
1 2 3 4
11 222 33 44 update a1 set a1.b=222 where a1.b=22
是否正确?
4,请问我这样写
select a1.*,a2.* from a1,a2 where a1.a=a2.a and a1.b=2
和我 select a1.*,a2.* from a1,a2 where a1.b=2
是否一致,感觉好象第2句有语法错误,但我这里没数据库,试不了请各位看看
a1
a b c d
1 2 3 4
11 22 33 44a2
a b c
1 2 3
11 22 33
由于这里没有数据库,所以我想问一下:
1,如果我在a1中插入2个数据,是不是
insert into a1(a,b,c,d)
values('aa','bb','cc','dd')
insert into a1(a,b,c,d)
values('aaa','bbb','ccb','ddd')
这样要执行2次,请问直接写一句insert into 是否可以。
2,请问我要删除表a1中的第一行数据变为
a b c d
11 22 33 44
delete from a1 where a1.a=1
是否正确?
3,如果要修改a1中字段b的数据使的b的第2行变成222
a b c d
1 2 3 4
11 222 33 44 update a1 set a1.b=222 where a1.b=22
是否正确?
4,请问我这样写
select a1.*,a2.* from a1,a2 where a1.a=a2.a and a1.b=2
和我 select a1.*,a2.* from a1,a2 where a1.b=2
是否一致,感觉好象第2句有语法错误,但我这里没数据库,试不了请各位看看
2.这样比较危险,可能删除不该删的数据,最好一个或多个不会重复的主键 where 主键=...
3.同2
4.结果不一样,第二句会多出一些数据,这种多表查询要把连接条件写完整,否则会出现冗余数据,它会做个乘法。
2. 语法正确
3. 正确,不过可以不加a1.直接写成 update a1 set b=222 where b=22
4. 第1句的结果是
a1.a a1.b a1.c a1.d a2.a a2.b a2.c
1 2 3 4 1 2 3
第2句的结果是
a1.a a1.b a1.c a1.d a2.a a2.b a2.c
1 2 3 4 1 2 3
11 22 33 44 1 2 3
如果两个表没有关联的话,就不要同时从两个表中取数据
2. delete from a1 where a=11;
3. update a1 set b=222 where b=22
4. select a1.*,a2.* from a1,a2 where a1.a=a2.a and a1.b=2
和select a1.*,a2.* from a1,a2 where a1.b=2
的不同点是select a1.*,a2.* from a1,a2 where a1.b=2少一层判断,就是a1.a=a2.a and a1.b=2,理论上,前者所得到的结果集<=后者。
然后
delete from a1 where 主键字段=...
update a1 set b=222 where 主键字段=...
2 正确
3正确
4不一制但是语法没错误