什么没有 发表于 2016-10-21 04:30:09

mysql语句在web中用到的语法

   
  创建表:create table `表名`(表名是用esc键下面的单引号括起来的)
  如果在建表中忘了设置外键的话,可以通过语句:
  alter table 表名 add primary key('id')来实现。
  修改表名:ALTER TABLE `旧表名` RENAME TO `新表名`;
  删除表:drop table 表名(回车)
  查看表中字段:desc 表名(回车)
  查看表中数据:
  select * from 表名;(回车)
  select id,name from 表名;(查看表中的id,name字段)
  select *from 表名 where id《=3(查看id小于等于3的数据)
   
  给表添加数据:
  insert into 表名(字段1,字段2,···)
  values(’数据1‘,’数据2‘,···)(这里的数据是用单引号括起来的)
   
  给表添加外键:
  alter table `bloginfo` add constraint `FK-bloginfo-uid`
  foreign key `FK-bloginfo-uid`('id-user')
  references 'bloginfo' ('id')
  on delete cascade
  on update cascade;
  以上语句会在名为bloginfo的表上加一个名为`FK-bloginfo-uid`的外键引用约束。
   
  删除表中字段:
  alter table 表名,(回车)
  drop column 字段名;
   
  增加表中字段:
  alter table 表名,(回车)
  add  字段名  类型
   
  修改字段名称:
  alter table `user` change column `要修改的字段名` `修改后的字段名` 数据类型 
  修改表中字段的数据:update 表名 set 字段1=‘x’ where id=y
  以上语句是将 id=y 的数据中的  字段1改为x
   
  删除表中字段的数据:
  delete from 表名 where id》=x
   删除id大于等于x的数据
   
页: [1]
查看完整版本: mysql语句在web中用到的语法