code1:建表
create talbe if not exsits disk.t_directories
(
id int(11) not null auto_increment,
user varchar(25) not null,
path varchar(255) not null,
parent_path varchar(255) not null,
dir varchar(20) not null,
create_time datetime not null,
primary key(id),
unique key user (user,path)
)engine=InnoDB default charset=utf8 collate=utf8_unicode_ci;
问题1:unique key user (user,path),这里应该是定义组合键(user,path)为unique,那这个user是什么意思,约束名吗?
问题2:有一个职工表,现在要使用一SQL语句,使得该职工表按男,女分组
如果用select * from employees where gender='男';只能得到男职工表
要得到一个按男,女分组的表,该SQL语句该如何写?
create talbe if not exsits disk.t_directories
(
id int(11) not null auto_increment,
user varchar(25) not null,
path varchar(255) not null,
parent_path varchar(255) not null,
dir varchar(20) not null,
create_time datetime not null,
primary key(id),
unique key user (user,path)
)engine=InnoDB default charset=utf8 collate=utf8_unicode_ci;
问题1:unique key user (user,path),这里应该是定义组合键(user,path)为unique,那这个user是什么意思,约束名吗?
问题2:有一个职工表,现在要使用一SQL语句,使得该职工表按男,女分组
如果用select * from employees where gender='男';只能得到男职工表
要得到一个按男,女分组的表,该SQL语句该如何写?
col_name column_definition
| [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...)
[index_option] ...
| {INDEX|KEY} [index_name] [index_type] (index_col_name,...)
[index_option] ...
| [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY]
[index_name] [index_type] (index_col_name,...)
[index_option] ...
| {FULLTEXT|SPATIAL} [INDEX|KEY] [index_name] (index_col_name,...)
[index_option] ...
| [CONSTRAINT [symbol]] FOREIGN KEY
[index_name] (index_col_name,...) reference_definition
| CHECK (expr)语法说明上很清楚, [index_name] 索引名!
如果用select * from employees where gender='男';只能得到男职工表
要得到一个按男,女分组的表,该SQL语句该如何写?select * from employees order by gender