sql语言基础总结

首先进去语句:cmd,mysql -uroot -p  然后就是密码;等进去一会一些简单的操作不做总结,
插入语句:insert into “table”(“属性”,······);values(“‘属性值’”,·······);
更新语句:update  “table” set “属性”=“‘属性值’” where “属性值”=?;
删除表:delete from “table” where “属性”=?;(支持事物)
删除表(2):truncate table “table” ;不支持事物  物理删除 无法恢复
查询语句:select “要查询的属性” from t “table” where “条件语句”(and or in);
指定别名:select “别名table”.“属性值” as “更改后的别名”  from “table” “别名table”
修改主键:alter table “table” add primary key “要变成主键的属性”;
外键概念:比如:一个用户表中 有个id  又有一个文章信息表  其中的一个author的属性就要加外键 将用户表的id设为外键,那么当用户中的数据被删除一个时  那么文章表的数据也要被删除
外键语句;alter table “文章信息表” add constraint “‘属性名’”
Foreign key “‘属性名’”(“‘加外键的属性名称’”)
Reference “‘table’” (“‘主键’”)
On delete cascade
On update cascade;
取消外键约束:alter table “‘table(文章)’” drop foreign key “‘属性名’” ;
唯一性约束:alter table “table” add unique index Index_unique using hash(“‘属性’”);
取消约束:alter table “table” drop  index ‘Index_unique’;
加索引;alter table “table” add add index Index_title using BTREE(“‘属性’”);
取消约束:alter table “table” drop  index ‘Index_title’;
更新表结构:
  增加一行:alter table“table”
  Add (创表属性语句)
  删除一列:alter table “table”
  Drop column “属性”
  删除整个表: drop table “table”;
最后还有一个导出语句:注意是cmd mysqldump -uroot -p “database”+“table” > 文件地址
导入语句:先进去数据库 建立一个表  之后是cmd
mysql  localhost -u root -p “创建的表名” <文件路径

猜你喜欢

转载自ligang7895123.iteye.com/blog/1839152