MySQL语句

1.创建表
create table Car
(
        Code varchar(50) primary key ,
        Name varchar(50) not null,
        Time date,
        Price float,
        Brand varchar(50) references Brand(Code)
);
create table Brand
(
        Code varchar(50) primary key ,
        Name varchar(50)
)


自增长

create table PinPai
(
       Ids int auto_increment primary key,
       Name varchar(50)
)

primary key 主键
not null 非空
reference 引用
auto_increment 自增长

注意: 所有符号必须是英文状态下的  
       每个表创建完之后加分号
       每个表里面的最后一列写完之后不要加逗号

删除表:
      drop table PinPai

数据的操作:CRUD操作  增删改查
 create 创建    read  读取  update修改     delete 删除

1.添加数据:
insert into Brand values('b001','宝马5');  #第一种方式
insert into Brand (Code) values('b002');  #第二种方式

insert into PinPai (Name) values('大众');
insert into PinPai value('','大众');    #处理自增长列

2.最简单查询
select * from PinPai  #查询所有数据
select * from PinPai where Ids = 1;  #根据条件查询

3.修改数据

update PinPai set Name = '保时捷' where Ids = 4; #修改某一条数据

update Car set Name = '哈弗', Time = '2012-3-4',Price = 16,Brand = 'b002' where Code = 'c001'

4.删除数据
delete from Brand  #删除所有数据
delete from PinPai where Ids = 4;  #根据条件删除数据

  

posted @ 2016-05-08 16:53  陌上初薰  阅读(122)  评论(0编辑  收藏  举报