The basic syntax sql

  • Create create create a database, data tables
  • Insert into insert inserted into the recording / tuple
  • Delete Delete drop databases, tables, records delete from deleting records
  • Query select Search record
  • Information Modify modify alter table
  • Update update update record / tuple

Alter syntax
alter database / table database name / data operation table
operation has

  • add
  • change
  • modify
  • drop

database

create

create database 数据库名;

delete

drop database 数据库名;

data sheet

create

create table 数据表名(属性 类型,属性,类型);

delete

drop table 数据表名;

Increase Column

alter table 数据表名 add column 列名 类型;

Remove Columns

alter table 数据表名 drop column 列名

Modify column properties

alter table 数据表名 modify 列名 类型
alter table 数据表名 change 列名 新列名 类型
modify和change的区别是一个只修改列的类型,一个还修改列名

Modify the table name

alter table 数据表名 rename to 新数据表名

recording

Add to

全部数据添加
insert into 数据表名 values();
部分数据添加
insert into 数据表名 () values();

Delete Record

delete from 数据表名;
delete from 数据表名 where 条件;

Modify records

update 数据表名 set xx = xx where xx =xxx

constraint

Add Constraint

alter table 数据表名 add 约束(列名);
alter table 数据表名 add constraint 约束名 约束(列名)

添加主键约束
alter table 数据表名 add constraint 约束名 primary key(列名); 

添加外键约束
alter table 从表名 add constraint 约束名 foreign key 从表(外键字段) references 主表(主键字段);

添加检查约束
alter table 数据表名 add constraint 约束名 check(条件);

添加唯一性约束
alter table 数据表名 add constraint 约束名 unique(列名)

添加默认约束(没必要加约束名)
alter table 数据表名 alter 列名 set default 默认值

The only constraint and primary key constraint difference

Primary key constraint does not allow null, null uniqueness constraint may be made, but at most only one null
of each table can be uniquely bound by a plurality of, but at most only one primary key constraint


When the constraint Unnamed time, automatically adding constraints, table names _chk_1
and primary keys, delete (auto-naming) constraint names no longer appear
can show create table 数据表名view the restriction of the
primary key constraint is only one, directly with no constraint name the constraints can be deleted
delete constraints

没有约束名的话(对于主键约束来说,其他约束不唯一)
alter table 数据表名 drop 约束;

有约束名的话
alter table 数据表名 drop 约束 约束名; 

Guess you like

Origin www.cnblogs.com/Emcikem/p/11829534.html