精华内容
下载资源
问答
  • i have this:DROP TABLE IF EXISTS `sf_guard_user`...CREATE TABLE `sf_guard_user`(`id` INTEGER(11) NOT NULL AUTO_INCREMENT,`username` VARCHAR(128) NOT NULL,PRIMARY KEY (`id`),UNIQUE KEY `sf_guard_user_U...

    i have this:

    DROP TABLE IF EXISTS `sf_guard_user`;

    CREATE TABLE `sf_guard_user`

    (

    `id` INTEGER(11) NOT NULL AUTO_INCREMENT,

    `username` VARCHAR(128) NOT NULL,

    PRIMARY KEY (`id`),

    UNIQUE KEY `sf_guard_user_U_1` (`username`)

    )Type=InnoDB;

    DROP TABLE IF EXISTS `shop_orders`;

    CREATE TABLE `shop_orders`

    (

    `orders_id` INTEGER(11) NOT NULL AUTO_INCREMENT,

    `sfgu_id` INTEGER(11) NOT NULL,

    PRIMARY KEY (`orders_id`),

    INDEX `shop_orders_FI_1` (`sfgu_id`),

    CONSTRAINT `shop_orders_FK_1`

    FOREIGN KEY (`sfgu_id`)

    REFERENCES `sf_guard_user` (`id`)

    ON UPDATE SET NULL

    ON DELETE SET NULL,

    )Type=InnoDB;

    and I'm getting this error:

    1005 - Can't create table

    'prueba1.shop_orders' (errno: 150)

    if i do not remove the lines ON UPDATE SET NULL and ON DELETE SET NULL.

    Any idea why?

    Regards

    Javi

    解决方案

    I think that is because you declared the field NOT NULL

    展开全文
  • 我有这个:DROP TABLE IF EXISTS `sf_guard_...CREATE TABLE `sf_guard_user`(`id` INTEGER(11) NOT NULL AUTO_INCREMENT,`username` VARCHAR(128) NOT NULL,PRIMARY KEY (`id`),UNIQUE KEY `sf_guard_user_U_1` (`u...

    我有这个:

    DROP TABLE IF EXISTS `sf_guard_user`;

    CREATE TABLE `sf_guard_user`

    (

    `id` INTEGER(11) NOT NULL AUTO_INCREMENT,

    `username` VARCHAR(128) NOT NULL,

    PRIMARY KEY (`id`),

    UNIQUE KEY `sf_guard_user_U_1` (`username`)

    )Type=InnoDB;

    DROP TABLE IF EXISTS `shop_orders`;

    CREATE TABLE `shop_orders`

    (

    `orders_id` INTEGER(11) NOT NULL AUTO_INCREMENT,

    `sfgu_id` INTEGER(11) NOT NULL,

    PRIMARY KEY (`orders_id`),

    INDEX `shop_orders_FI_1` (`sfgu_id`),

    CONSTRAINT `shop_orders_FK_1`

    FOREIGN KEY (`sfgu_id`)

    REFERENCES `sf_guard_user` (`id`)

    ON UPDATE SET NULL

    ON DELETE SET NULL,

    )Type=InnoDB;

    我收到这个错误:

    1005 – Can’t create table

    ‘prueba1.shop_orders’ (errno: 150)

    如果我不删除ON UPDATE SET NULL和ON DELETE SET NULL行.

    知道为什么吗?

    问候

    哈维

    展开全文
  • 外键约束 SET NULL

    2021-01-30 01:37:39
    定义子表 CREATE TABLE users2( id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, username VARCHAR(10), pid SMALLINT UNSIGNED, FOREIGN KEY (pid) REFERENCES provinces (id) ON UPDATE SET NULL );...

    定义父表

    CREATE TABLE provinces(

    -> id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,

    -> pname VARCHAR(20) UNSIGNED

    -> );

    插入3个值

    INSERT provinces(pname) VALUES('A');

    INSERT provinces(pname) VALUES('B');

    INSERT provinces(pname) VALUES('C');

    定义子表

    CREATE TABLE users2(

    id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT,

    username VARCHAR(10),

    pid SMALLINT UNSIGNED,

    FOREIGN KEY (pid) REFERENCES provinces (id) ON UPDATE SET NULL

    );

    插入值

    INSERT users2(username,pid) VALUES('Tom',3);

    INSERT users2(username,pid) VALUES('Jon',2);

    INSERT users2(username,pid) VALUES('Kang',3);

    删除父表第3列报错!!!!!!!

    DELETE FROM provinces WHERE id=3;

    错误如下:

    ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails (`test`.`users2`, CONSTRAINT `users2_ibfk_1` FOREIGN KEY (`pid`) REFERENCES `provinces` (`id`) ON UPDATE SET NULL)

    求助:这是为什么呢,我子表的外键列pid并没有设置为NOT NULL,为什么这个外键不生效呢?删除不了父表来更新。

    展开全文
  • MySqlCommand cmd = new MySqlCommand("Update images set Name=@Name,Content=@Content where ID="+ID, con); cmd.Parameters.Add("@ID", MySqlDbType.Int16).Value = ID; cmd.Parameters.Add("@Name", ...

    protected void GVImages_RowUpdating(object sender, GridViewUpdateEventArgs e)

    {

    string ID = ((Label)GVImages.Rows[e.RowIndex].FindControl("lblID")).Text;

    string Name = ((TextBox)GVImages.Rows[e.RowIndex].FindControl("txtName")).Text;

    FileUpload f = ((FileUpload)GVImages.Rows[e.RowIndex].FindControl("FileUpload2"));

    byte[] imageBytes = null;

    if (f.HasFile)

    {

    //variable to store the image content

    imageBytes = new byte[f.PostedFile.ContentLength];

    HttpPostedFile uploadImage = f.PostedFile;

    //read the image stream from the post and store it in imageBytes

    uploadImage.InputStream.Read(imageBytes, 0, (int)f.PostedFile.ContentLength);

    }

    con.Open();

    MySqlCommand cmd = new MySqlCommand("Update images set Name=@Name,Content=@Content where ID="+ID, con);

    cmd.Parameters.Add("@ID", MySqlDbType.Int16).Value = ID;

    cmd.Parameters.Add("@Name", MySqlDbType.VarChar).Value= Name;

    cmd.Parameters.Add("@Content", MySqlDbType.LongBlob).Value = imageBytes;

    cmd.Connection = con;

    cmd.ExecuteNonQuery();

    GVImages.EditIndex = -1;

    con.Close();

    databind();

    }

    解决方案Try replaceing

    MySqlCommand cmd = new MySqlCommand("Update images set Name=@Name,Content=@Content where ID=" +ID, con);

    with

    MySqlCommand cmd = new MySqlCommand(" Update images set Name=@Name,Content=@Content where ID=@ID", con);

    Basically, ExecuteNonQuery() method should return you an integer, but you don''t catch it in any variable in your code ; you can watch its value by debugging, either.

    The question you should concentrate on is : What do you want to get from an UPDATE command ?

    Do you expect to get a resultset (i.e., one or more rows) ? You won''t.

    If you want to get a resultset from a query, it must be a SELECT one.

    So, please, we need to know what exactly you are expecting from your SQL request.

    As ThePhantomMenace pointed out, you are concatenating on the ID in the string but then are adding a parameter named @ID. You need to change the SQL command text to be

    "Update images set Name=@Name,Content=@Content where ID=@ID"

    展开全文
  • update 要加where ,要加where,要加where。 先创建两个测试表: CREATE TABLE test_001 ( id VARCHAR2(10) not null, NAME VARCHAR2(10) ) CREATE TABLE test_002 ( id VARCHAR2(10) n
  • 问题I have this query on Oracle 10g:UPDATE "SCHEMA1"."CELLS_GLIST"SET ("GLIST_VALUE_ID", "USER_ID", "SESSION_ID") = (SELECT "GLIST_VALUE_ID", 1 AS "USER_ID", 123456 AS "SESSION_ID"FROM "SCHEMA1"....
  • NULL字段不更新 <update id="updateConfig" parameterType=...set> <if test="configName != null and configName != ''">config_name = #{configName},</if> <if test="configKey != null an
  • update 表名 set belongSysCode = 'DSJJQ' where useFor = '大数据集群' and belongSysCode ='' OR belongSysCode = ''; 上边的语句执行不会报错,但是也没有成功 将 where 条件中的改为: belongSysCode is null,...
  • 我就废话不多说了,大家还是直接看代码吧~UPDATE customer setname=#{name,jdbcType=VARCHAR},role=#{role,jdbcType=VARCHAR},user_id = #{userId,jdbcType=INTEGER},qq = #{qq,jdbcType=VARCHAR},mobile = #{mobile...
  • 在讲null之前,我们先...+------+-------+| id | name |+------+-------+| 1 | chen || 2 | zhang || 3 | NULL |+------+-------+3 rows in set (0.00 sec)然后我们想查出所有名字不为'chen'的其它行记录,我们有可...
  • @TableField(updateStrategy = FieldStrategy.NOT_NULL) private Integer showSort;
  • MySQL NULL详细和应用

    千次阅读 2021-01-27 18:18:09
    在本教程中,您将学习如何使用MySQL NULL值。 此外,您将学习一些有用的函数来有效地处理NULL值。如果不能理解和使用数据库中NULL值,那么可以认为您的数据库学习最多算刚入门水平。MySQL NULL值简介在MySQL中,NULL...
  • 本章节是mybatis中使用update配置及set动态语句操作,实现对用户的资料进行修改 映射配置:update片段 动态SQL配置:set配置 先梳理下之前开发的项目,在用户详情页可以查看用户的详细信息,所以对用户的资料进行修改...
  • mysql update语句的用法详解

    千次阅读 2021-01-18 21:12:50
    本文详细介绍了,mysql中update语句的用法,系统全面的学习下update更新语句的用法,有需要的朋友可以参考下首先,单表的UPDATE语句:UPDATE [LOW_PRIORITY] [IGNORE] tbl_nameSET col_name1=expr1 [, col_name2=...
  • 接口 //更新数据 int updateBlog(Map map); 接口配置文件 ...update id="updateBlog" parameterType="map">...set> <if test="title!=null"> title=#{title}, </if> <if test="au
  • update usr_wms_city.con_content x set x.qty =(selectnvl(j.qty,0)from (select locno,a.cell_no,a.size_no,a.item_no,a.barcode,a.item_type,a.quality,max(a.createtm)createtm,sum(a.qty)qty f...
  • 第一个:CREATE TABLE IF NOT EXISTS address(address_id INT NOT NULL AUTO_INCREMENT,address_region VARCHAR(10) NOT NULL,address_country VARCHAR(20) NOT NULL,address_city VARCHAR(30) NOT NU...
  • 查询数据库记录报错: 错误信息: Can not set int field /*某个类的属性*/ to null value 不能设置int类型的属性为null值 原因就是:数据库中有类型为int的字段未赋值 改了之后,执行成功
  • 表tenant_oper结构:create table `tenant_oper` (`id` int(11) not null auto_increment,`oper_name` varchar(255) not null,`oper_code` varchar(255) not null,`remark` varchar(512) default "",`menu_id` int ...
  • int update = disAddressListMapper.update( null, Wrappers.<DisAddressList>lambdaUpdate() .set(DisAddressList::getBlacklistFlag, 1) .set(DisAddressList::getBlacklistReason,
  • 使用SQL中的UPDATE关键字更新多个字段值时,SET后面的更新字段应该使用逗号而不能用AND。虽然用AND不会报错,但会使更新结果错误,下面我将通过场景来分析当我们使用AND时SQL的执行过程和为什么更新结果只会是0/1/...
  • I wanted to test by using command, UPDATE employee SET salary=NULL; Query OK, 15 rows affected, 15 warnings (0.06 sec) Rows matched: 15 Changed: 15 Warnings: 15 also gave warnings " (Code 1048): ...
  • 我有以下触发器:DELIMITER $$CREATE TRIGGER user_update_trigger BEFORE UPDATE ON `users` FOR EACH ROWBEGINIF (NEW.type != OLD.type or NEW.agency_name != OLD.agency_name) and NEW.type = 'INDEPENDENT' ...
  • 去百度了一波说用updateStrategy = FieldStrategy.IGNORED,然后在实体类对应属性添加了updateStrategy = FieldStrategy.IGNORED,再执行了一波,发现需要设置为null的字段确实生效了,但是没有需要修改的字段也被...
  • MySQL更新列为NULL的空白值

    千次阅读 2021-01-19 03:26:09
    为此,可以IF()与UPDATE命令一起使用。让我们首先创建一个表-mysql>createtableDemoTable1601->(->FirstNamevarchar(20),->LastNamevarchar(20)->);使用插入命令在表中插入一些记录-mysql>...
  • 今天我们踩到一个collect_list的坑,collect_list的结果不包含null值 name city 张三 广州 null 广州 李四 深圳 对city作group by后collect_list(name)得到的结果中city='广州’为List(‘张三’),...
  • Object[] params = null; //1.错误 Object[] params = {};//2.正确 1.通过第一种方式传参会报空指针异常,正确设置参数为空的方式是第二种 for (int i = 0; i < params.length; i++) { //setObject 用于设置...
  • update article set body = (REPLACE(body, '', ' ')) wheretypeid=21用update和replace在mysql中替换某一个字段的部分内容update users_settings set `ConfigValue` =replace(configvalue,'fromstr' 'tostr') where...
  • 使用SQL中的UPDATE关键字更新多个字段值时,SET后面的更新字段应该使用逗号而不能用AND。虽然用AND不会报错,但会使更新结果错误,下面我将通过场景来分析当我们使用AND时SQL的执行过程和为什么更新结果只会是0/1/...
  • mybatis update set if

    2021-03-04 09:37:23
    <update id="updateNotebookMaterial" parameterType="NotebookMaterial">...set> <if test="notebookMaterial.purpose != null and notebookMaterial.purpose != ''"> PURPOSE .

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 639,354
精华内容 255,741
关键字:

nullsetupdate