sql 语句_基本操作

上一篇 / 下一篇  2008-05-10 00:22:14 / 个人分类:数据库

操作数据库:

1.创造数据库:Create database database_name;

2.删除数据库:Drop database database_name;

3.创建新表:create table tabel_name(col1 type1 [not null] [primary key], col2 ...);

  以旧表创建新表:create table table_name_new like tab_old

               create table table_new as select col1,col2,..from tab_old definition  only;

4.删除表:drop table table_name;

5.增加列:alter table table_name add column colname typename

  删除列 alter table table_name drop column coluname

6.添加主键:alter table table_name add primary key (colName)

  删除主键:alter table table_name drop primary key(colName)

7.创建索引:create [unique]index indexName on tableName(col...)

  删除索引:drop index indexName on tableName

8.创建视图:create view viewname as select_statement

  删除视图:drop view viewName

9.常用语句:选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’   排序:select * from table1 order by field1,field2 [desc]
总数:select count(field) as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1


TAG: SQL study db DB学习

 

评分:0

我来说两句

Open Toolbar