首页 > 数据库技术 > 详细

数据库操作学习

时间:2015-06-03 23:06:28      阅读:364      评论:0      收藏:0      [点我收藏+]

 

<1>创建新表
   sqlite>create  table  <table_name>  (f1  type1, f2  type2,…);
        例如:
         create table  people(id,name,age);
 
<2>删除表
sqlite>drop  table  <table_name>
        例如:
        drop table people;
 
<3>向表中添加新记录
        sqlite>insert  into  <table_name>  values (value1, value2,…);
        例如:
        insert into people  values(1,‘A‘,10);
        insert into people  values(2,‘B‘,13);
        insert into people  values(3,‘C‘,9);
        insert into people  values(4,‘C‘,15);
        insert into people  values(5,NULL,NULL);
        注意: 字符串要用单引号括起来。
 
<4>查询表中所有记录
        sqlite>select  *  from  <table_name>;
        例如 :
        select   *   from  people;
 
<4>按指定条件查询表中记录
   sqlite>select  *  from  <table_name>  where  <expression>;
        例如:
        在表中搜索名字是A的项所有信息
         select  *  from  people  where  name=‘A‘;
       
         在表中搜索年龄>=10并且<=15的项的所有信息
        select  *  from   people  where age>=10  and  age<=15;
        
        在表中搜索名字是C的项,显示其name和age
        select name,age from people where name=‘C‘;
 
        显示表中的前2项所有信息
        select  *  from  people  limit  2;
        
        显示以年龄排序表中的信息
        select * from people  order by age;
        
<6>按指定条件删除表中记录
    
sqlite>delete  from  <table_name>  where  <expression>
        
        例如:
        删除表中名字是‘C‘的项
        delete from pople  where name=‘C‘;
 
<7>更新表中记录
 
        sqlite>update  <table_name>  set  <f1=value1>, <f2=value2>…   where  <expression>;  
        
        例如:
        将表中年龄是15并且ID是4项,名字改为CYG
        update  people set  name=‘cyg‘  where  id=4 and  age=15;
 
<8>在表中添加字段
  
        sqlite>alter table <table> add column <field> ;
        
        例如:
        在people表中添加一个addr字段
        alter table  people add column addr;
        
 

数据库操作学习

原文:http://www.cnblogs.com/lzh-Linux/p/4550354.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!