GVKun编程网logo

SQL SELECT WHERE字符串以Column结尾(select * from where 字段 in)

8

本文将为您提供关于SQLSELECTWHERE字符串以Column结尾的详细介绍,我们还将为您解释select*fromwhere字段in的相关知识,同时,我们还将为您提供关于Anexplicitva

本文将为您提供关于SQL SELECT WHERE字符串以Column结尾的详细介绍,我们还将为您解释select * from where 字段 in的相关知识,同时,我们还将为您提供关于An explicit value for the identity column in table 'users' can only be specified when a column list、Incorrect column specifier for column "id"、Laravel 中的 WhereColumn null、MySQL ALTER TABLE: ALTER COLUMN vs CHANGE COLUMN vs MODIFY COLUMN的实用信息。

本文目录一览:

SQL SELECT WHERE字符串以Column结尾(select * from where 字段 in)

SQL SELECT WHERE字符串以Column结尾(select * from where 字段 in)

我在SQL Server 2012中有此表:

Id INT 
DomainName NVARCHAR(150)

该表具有这些DomainName值

  1. google.com
  2. microsoft.com
  3. othersite.com

而这个值:

mail.othersite.com

并且我需要选择字符串以列值结尾的行,为此值我需要获取第3行。othersite.com

就像这样:

DomainName Like '%value'

但是相反…

'value' Like %DomainName

An explicit value for the identity column in table 'users' can only be specified when a column list

An explicit value for the identity column in table 'users' can only be specified when a column list

eclipse中tomcat console提示如下:

An explicit value for the identity column in table ''users'' can only be specified when a column list is used and IDENTITY_INSERT is ON. 


users中的字段有:userid,username,passwd,grade

原始:

String sqlUpdate="insert into users values (null,?,?)";

数据库为sqlserver2008R2

由于users中的userid设置为自动增长,所以不需要在插入时设置该值,修改为:

String sqlUpdate="insert into users values (?,?)";

Incorrect column specifier for column

Incorrect column specifier for column "id"


用Hibernate生成数据表时,Hibernate执行了下面的SQL语句:

Incorrect column specifier for column "id"

是 我设置的主键 是自动增长

@Id

@GenerateValue

但是,主键的类型却不是int 类型!

所以,表没有自动建成功!!!


Laravel 中的 WhereColumn null

Laravel 中的 WhereColumn null

如何解决Laravel 中的 WhereColumn null?

我需要比较表中的两列,但如果最少一列为空,则查询返回空。

id 姓名 original_price sale_price
1 洗发水 2.30 NULL
$this->products = Product::whereColumn(''original_price'',''!='',''sale_price'')->get();

解决方法

如果你希望这样的查询也返回 Null 值,你应该使用 orWhereNull

$this->products = Product::whereColumn(''original_price'',''!='',''sale_price'')
            ->orWhereNull("original_price")
            ->orWhereNull("sale_price")
            ->get()

顺便说一句:如果两者都为 Null,则字段相等但查询不会为空

,

只需在两列上添加 whereNotNull,如果其中一个为 null,则查询 where 条件不匹配且不返回记录

 $this->products = Product::whereColumn(''original_price'',''sale_price'')
            ->whereNotNull("original_price")
            ->whereNotNull("sale_price")
            ->get()

MySQL ALTER TABLE: ALTER COLUMN vs CHANGE COLUMN vs MODIFY COLUMN

MySQL ALTER TABLE: ALTER COLUMN vs CHANGE COLUMN vs MODIFY COLUMN

ALTER TABLE 允话使用 ALTER COLUMN 、 CHANGE COLUMN 和 MODIFY COLUMN 修改列,这三种操作是不一样的,下面做简单的对比。

ALTER COLUMN:设置或删除列的默认值。该操作会直接修改.frm 文件而不涉及表数据。此操作很快

ALTER TABLE  MyTable ALTER COLUMN xxx SET DEFAULT 100;

--  共 0 行受到影响
--
-- 执行耗时   : 0.011 sec
-- 传送时间   : 1.037 sec
-- 总耗时      : 1.048 sec
-- ---------------------------------------------------

CHANGE COLUMN: 列的重命名、列类型的变更以及列位置的移动(应该也会引起表的重建,非常慢)
语法:CHANGE [COLUMN] old_col_name new_col_name column_definition [FIRST|AFTER col_name]

 ALTER TABLE  MyTable CHANGE COLUMN xxx xxx INT FIRST
--  共 2000000 行受到影响
--
-- 执行耗时   : 12.037 sec
-- 传送时间   : 1.074 sec
-- 总耗时      : 13.012 sec
-- ---------------------------------------------------

MODIFY COLUMN:除了列的重命名之外,他干的活和 CHANGE COLUMN 是一样的(会引起表的重建,非常慢)

 ALTER TABLE  MyTable MODIFY COLUMN xxx  INT NOT NULL DEFAULT 101;
--  共 2000000 行受到影响
--
-- 执行耗时   : 13.066 sec
-- 传送时间   : 0.001 sec
-- 总耗时      : 13.067 sec
-- ---------------------------------------------------

关于SQL SELECT WHERE字符串以Column结尾select * from where 字段 in的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于An explicit value for the identity column in table 'users' can only be specified when a column list、Incorrect column specifier for column "id"、Laravel 中的 WhereColumn null、MySQL ALTER TABLE: ALTER COLUMN vs CHANGE COLUMN vs MODIFY COLUMN等相关内容,可以在本站寻找。

本文标签: