基本语句

---------------------------------------数据库---------------------------------------
创建表
create table TABLE_NAME(
 'id' int(10) NOT NULL,
 'name' varchar(30) default NULL,
 'address' varchar(100) default NULL,
 PRIMARY KEY ('id')
)
修改表名
rename table TABLE_NAME_OLD to TABLE_NAME_NEW;
创建视图
create view VIEW_NAME as select * from TABLE_NAME;
select * from VIEW_NAME;
创建索引
create index INDEX_NAME on TABLE_NAME (COLUMN_NAME);
倒序查询
select * from TABLE_NAME order by column desc;
查询前5
select * from TABLE_NAME limit 5;
查询5到10行
select * from TABLE_NAME limit 4,6;
删除数据不删除表结构
delete from TABLE_NAME;
删除表数据和结构
drop table TABLE_NAME;
更新表数据
update TABLE_NAME set column= where column=;
update TABLE_NAME set column= where column is null;
表中插入列
alter table TABLE_NAME add (column datatype);
表中更新列
alter table TABLE_NAME change column_old column_new datatype;
表中删除列
alter table TABLE_NAME drop column;
插入表
insert into TABLE_NAME (column1,column2,column3) values ("","","");
多表查询:单个字段相同
select n.natmode,s.sipstackip from sipstackaddrconfig s,natconfig n where s.id=n.id
多表查询:多字段相同
select n.natmode,s.sipstackip from sipstackaddrconfig s join natconfig n using (id)
select n.natmode,s.sipstackip from sipstackaddrconfig s,natconfig n group by s.id

猜你喜欢

转载自syyzxq.iteye.com/blog/2215041
今日推荐