记一些T-SQL/PL-SQL和Sql Server/MySql以及Linq相关的笔记,备查
Q:获取指定数据库的所有表信息:
MySql:
SELECT * FROM information_schema.TABLES WHERE table_schema = 'qingcoredb'
Sql-Server:
SELECT * FROM
[qingcoredb].INFORMATION_SCHEMA.TABLES WHERE
TABLE_TYPE = 'BASE TABLE'
Q:获取指定表的所有字段信息:
MySql:
SELECT TABLE_SCHEMA , TABLE_NAME, COLUMN_NAME, DATA_TYPE , COLUMN_COMMENT FROM `information_schema`.`COLUMNS` WHERE `TABLE_SCHEMA` = 'qingcoredb' AND `TABLE_NAME` = 'account' ;
sql-server:
SELECT * FROM [qingcoredb].INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'account'
Q:指定字段添加默认值:
ALTER TABLE account MODIFY IsActived INT(1) DEFAULT 1;
Q:EF DateTime 默认值多数据兼容问题:
mysql:NOW()或sysdate()
Sql Server: GetDate()
EF兼容使用 ANSI SQL:
builder.Property(x => x.UpdatedOn).HasDefaultValueSql("CURRENT_TIMESTAMP");