create database my-database
1
drop database my-database
1
create table my_table(col1 type1 [not null] [primary key],col2,type2 [not null] [primary key],...)
1
create table new_table like old_table
1
drop table my_table
1
列增加后不能删除。DB2中列加上后数据类型也不改变,唯一能改变的是增 加 varchar 类型的长度。
Alter table my_table add column col type
1
Alter table my_table add primary key(col)
1
Alter table my_table drop primary key(col)
1
create [unique] index inx on my_table(col...)
1
drop index inx
1
create view my_view as select statement
1
drop view my_view
1
选择:select * from my_table where 条件
插入:insert into my_table (field1,field2) values (value1,value2)
删除:delete from my_table where 条件
更改:update my_table set field1 = value1 where 条件
查找:select * from my_table where field1 like ‘%value1’
排序:select * from my_table order by field1,field2 [desc]
总数:select count * as totalcount form my_table
求和:select sum(field1) as sumvalue from my_table
平均:select avg(field1) as avgvalue from my_table
最大:select max(field1) as maxvalue from my_table
最小:select min(field1) as minvalue from my_table
1.链接数据库
$conn=@mysql_connect("localhost","root","root");
if(!$conn){
die("数据库连接失败",mysql_error())
}else{
echo"数据路连接成功"
}123456
2.选择数据库
mysql_select_db("web",$conn)
1
3.执行 sql 语句
$query=mysql_query("select * from 表名 where 1")
1
4.操作 sql 结果
while($row=mysql_fetch_assoc($result)){
print_r($row);
echo "<br>";
}1234
5.关闭 mysql 链接
mysql_close($conn)