sql常用的基本语法(修改表名,修改表字段,修改字段类型,增加表字段,查找,修改,删除) |
您所在的位置:网站首页 › 数据库如何修改表名称格式 › sql常用的基本语法(修改表名,修改表字段,修改字段类型,增加表字段,查找,修改,删除) |
更改表名:
alter table 旧表名 rename 新表名。 比如:alter table t_t_user rename t_user; 修改表类型:alter table 表名 modify 你需要修改的字段名称和类型。 比如: alter table t_user modify id int(10) 增加表字段:alter table 表名 add column 你需要增加的字段和类型 删除表字段:比如: alter table t_user add column age int(2); alter table 表名 drop 你需要删除的字段 比如:alter table t_user drop age; 字段改名alter table 表名 change 旧的字段名 新的字段名和类型 比如:alter table t_user change age ages int(2); 注意:change和modify都可以修改表的定义,不同的是change后面需要写两次列名,不方便。但是change的有点事可以修改列名称,modify则不能。 修改字段排列alter table 表名 add 新增字段名称和类型 after 你需要在新字段排序之前的字段 比如: alter table t_user add age int(11) after id; 插入: insert into 表名(字段名称1,字段名称2,,字段名称3,……) values(值1,值2,值3,……)。 比如:insert into t_user(user_name,password) values('admin','a123456'); 注意:如果有字段没有写,会自动设置成为null,如果你有字段不能为null,但是没有写,就会报错,添加不了数据 一次性插入多条: insert into 表名(字段名称1,字段名称2,,字段名称3,……)values(值1,值2,值3,……),(值1,值2,值3,……),(值1,值2,值3,……)。 比如:insert into t_user(user_name,password) values('admin1','a123456'),('admin2','a123456'),('admin3','a123456'); 更新:update 表名 set 字段名=需要更新的值 where 条件 比如:update t_user set password='123456' where id = 2 删除:delete from 表名 where 条件 比如:delete from t_user where id = 2\ 查询:select * from 表名 where 条件 (where如果没有表示查出的是这张表所有的数据) 比如:select * from t_user where id = 1 查询不重复的记录:使用distince关键字 select distinct 字段名 from 表名 比如:select distinct password from t_user; |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |