mysql

来源:互联网 发布:nginx安装和配置 编辑:程序博客网 时间:2024/05/22 09:37

SHOW INDEX from inventoryBase_items;   
  ALTER TABLE inventoryBase_items add INDEX baseID(baseId,warehouseCode,goodsBatch);
--add constraints
-- add primary key
alter table users add constraints users_id_pk primary key(id);
alter table user_infos add constraints user_infos_id_pk primary key(id);
alter table products add constraints products_id_pk primary key(id);
alter table orders add constraints orders_id_pk primary key(id);
alter table orderLines add constraints orderLines_id_pk primary key(id);

-- add foreign key
alter table user_infos add constraints user_info_id_fk foreign key(id) refencese users(id);
alter table orders add constraints orders_user_id_fk foreign key(user_id) refencese users(id);
alter table orderLines add constraints orderLines_order_id_fk foreign key(order_id) refencese orders(id);
alter table orderLines add constraints orderLines_product_id_fk foreign key(procudt_id) refencese product(id);

-- add uniue key
alter table users add constraints users_login_name unique(login_name);
alter table products add constraints products_code unique(code);
alter table orders add constraints orders_code unique(code);

-- add not null
alter table users modify login_name not null;
alter table procudts modify code not null;
alter table orders modify user_id not null;
alter table orders modify code not null;
alter table orderLines modify order_id not null;
alter table orderLines modify product_id not null;
-- add sequence
drop sequence my_key;
create sequence my_key

TRUNCATE 清除数据
比如你要将 表 tb1里面的 f1字段的abc替换为def

UPDATE tb1 SET f1=REPLACE(f1, 'abc', 'def');

原创粉丝点击