数据库语言简单总结
创建数据库:create database databasename;
创建表: create table mytable( `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(45) NOT NULL,
PRIMARY KEY(`id`));
删除数据库:drop database mydb;
删除表:drop table mytable;
查询数据库:show databases;
查询表:show tables;
查询字段:desc table mytable;
插入数据:insert into mytable valus(‘value1’,’value2’...);
Insert into mytable select * from mytable2;
删除数据:delete from table where id=90;
更新数据:update mytable set name=”zhangsan’ where id=90;
查询表内容:select * from mytable;
Select * from mytable order by id limit 100,10;
Select name as “姓名” order by id;
Select name “姓名” order by id;
精确查找:select * from students where native in (‘zhangsan ', '18');
.between...and:select * from students where age between 20 and 30
select * from students where name like '李%' (注意查询条件中有“%”,则说明是部分匹配,而且还有先后信息在里面,即查找以“李”开头的匹配项。所以若查询有“李”的所有对象,应该命令:'% 李%';若是第二个字为李,则应为'_李%'或'_李'或'_李_'。)
Select * from mytable order by age(按年龄增序排列)
Select * from mytable order by age desc(按年龄降序排列)
增加一列: alert table mytable add name varchar(20) not null;
删除一列: alert table mytable delete name
count()求总数,如:select count(*) from students (求学生总人数)
b.avg(列)求平均,如:select avg(mark) from grades where cno=’B2’
c.max(列)和min(列),求最大与最小