创建并使用数据库:
- MySQL
create database test;
use test;
向表中添加字段:
- MySQL
ALTER TABLE table1
ADD COLUMN col2 TINYINT(1) NOT NULL DEFAULT 0 COMMENT ‘xx’ AFTER col1;
添加索引:
- MySQL
alter table table1 add index idxCol(col);
sql语句修改表名:
5. MYSQL
rename table table1 to table2;
6. SQL SERVER
EXEC sp_rename ‘table1’, ‘table2’;
7. Oracle
alter table table1 rename to table2
8. db2
rename table table1 to table2;
sql语句查询指定数据库的所有表名:
select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA=‘数据库名’;
sql语句设置主键:
ALTER TABLE 表名 ADD CONSTRAINT PK_Syllabus PRIMARY KEY (要设为主键的列名);
sql语句修改列的数据类型为clob:
这里为修改表T_TABLE的列test_column:
alter table T_TABLE add test_column_A clob;
update T_TABLE set test_column_A = test_column;
alter table T_TABLE drop column test_column;
alter table T_TABLE rename column test_column_A to test_column;
对于日期类型的字段作为筛选条件可以:
select * from T where to_char(T.dateColumn,‘yyyy-mm-dd HH:MM’)=‘2017-12-12 12:12’
MySQL
8.0.11重置密码语句:
ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘你的密码’;
FLUSH PRIVILEGES;