--创建表 <字段名> <数据类型> unique --修改表 alter table 表名 add constraint 约束名 unique(列); --删除alter table <表名> drop index <唯一约束名>; 默认约束(default) 默认约束用于给表中字段指定默认值,即当在表中插入一条新记录时,如果没有给这个字段赋值,系统会自动为这个字段插入默认值。 代...
1、创建库:create database 【if not exists】库名 【character set 字符集名】 2、 修改库:alter database 库名 。。。 3、 删除库:drop database 【if exists】库名; 二、表的管理 1、创建表: create table 【if not exists】表名( 字段名 字段类型【约束】, 字段名 字段类型【约束】, ...) 2...
ALTER TABLE 表名 ADD CONSTRAINT 外键名称 FOREIGN KEY (外键字段名称) REFERENCES 主表名称(主表列名称); 1. 2. 删除外键约束 AI检测代码解析 ALTER TABLE 表名 DROP FOREIGN KEY 外键名称; 1. 1.8.3 练习 根据上述语法创建员工表和部门表,并添加上外键约束: AI检测代码解析 -- 删除表 drop table if e...
修改字段名称和字段类型 alter table <表名> change 旧字段名 新字段名 类型 [comment 注释][约束]; 3.删除 alter table <表名> drop 字段名; eg:删除 student 表中籍贯字段。 前 后 4.修改表名 alter table <表名> rename to 新表名; 5.删除表 删除表 drop table [if exists] 表名; 中括号里的...
id=a2.id;-- 2 DROP是删除数据库对象--- 2.1 删除表DROP[TEMPORARY]TABLE[IFEXISTS]tbl_name[...
drop table if exists tbl_user; create table tbl_user( id int, name varchar(32), birth date ); 插入数据。 insert into tbl_user(id,name,birth) values(1,'张三','01-10-1990'); -- 错误! 错误原因是类型不匹配,数据库birth是date类型,这里给了一个字符串varchar。 怎么办?可以使用str_to_...
/*在一张表中定义多个主键*/usestudents;droptableifEXISTSPersons;createtablePersons ( P_idintnotnull, P_Namevarchar(50), Cityvarchar(30),CONSTRAINTpk_PersonID_NamePRIMARYkey(P_id,P_Name) );descPersons; 语法:CONSTRAINT 主键约束的名称 PRIMARY key(字段1,字段2,...) 在...
alter table t_test2 add constraint fk1 foreign key (id) references t_test1(id); 1.14 删除外键 语法: show create table table_name; 获取外键名称: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 show create table t_test2; 语法:alter table t_test2 drop foreign key 外键名称; 代码语言:java...
constraint email_uniqueunique(email)/*表级约束*/) 主键约束,primary key 每个表应该具有主键,主键可以标识记录的唯一性,主键分为单一主键和复合(联合)主键,单一主键是由一个字段构成的,复合(联合)主键是由多个字段构成的。 drop tableifexists t_student;create tablet_student()student_idint(10)primary key,/...
alter table rg_product add constraint FK_Reference_4 foreign key (us_id) references rg_user (us_id) on delete restrict on update restrict; Query OK, 0 rows affected 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the ...