![]() |
![]() |
![]() |
发表:2025-04-29 01:46:54 浏览: |
1. 表操作1.建表 CREATE TABLE tableA ( id int(8) NOT NULL, user int(8) NOT NULL, topic varchar(20) NOT NULL, date int(10) NOT NULL, status int(1) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 2. 显示当前数据库的表 show tables; 3. 删除表 drop table tableA; 4. 更改表名 alter table old_tablename rename new_tablename;
2. 字段操作1. 添加字段(在itmeA字段之后) alter table tableA Add column new_itemB varchar(1) not null default 0 After itemA; 2. 修改字段名 alter table tablename change itemOld itemNew varchar(10) not null default 0 ; 3. 删除字段 ALTER TABLE tableA DROP COLUMN itemA 4. . 添加主键 ALTER TABLE tableA ADD PRIMARY KEY (id); 5. 设置主键,自动加一 ALTER TABLE tableA MODIFY id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
3. SQL文
3. SQL文1. //<内容>原本一个单引号,插入时需要写两个单引号 INSERT INTO tableA (id, text, date, status) VALUES (1, '内容1', 1670948493, 1), (2, '内容2', 1670948493, 1); UPDATE tableA SET id='1',text='内容' where id=1 and sub_id=1 DELETE FROM tableA WHERE id=5 and sub_id=1 3. 删除表中所有数据,不能加Where条件。#删除速度快 truncate table tableA