【问题标题】:MSSQL insertWITHRELATIONSHIPMSSQL 插入WITHRELATIONSHIP
【发布时间】:2016-01-24 07:28:10
【问题描述】:

我在使用关系键在我的 2 个表上插入记录时遇到错误。这是我的表格:

表名是 [tbl1]

Ccode bigint, (autoincrement) (not null) ----->relationship with tbl2
customerId varchar(5), (not null)   
CUstomerName varchar(50)

表名是 [tbl2]

User_Idx bigint, (autoincrement) (not null)
Ccode bigint, (autoincrement) (not null)  ----->relationship with tbl1 
callLogs bit, (yes/no or 0/1) (not null)
MyDateTime DateTime, (not null)
Duration smalldatetime, 
Description varchar20

这是我的插入查询,但没有用:(

insert into tbl1 values ('5055','Vangelyn De Castro')
insert into tbl2 values ('1','01/26/16 08:40', '24:12:00','Incoming Call')

【问题讨论】:

  • 这里有很多“腥”的东西;您在 SQL 中使用双引号 " 而不是单引号 ',您的时间为 24:12:00,这比一天中的时间还多,您不是说要插入哪些字段insert into tbl1(customerId, customerName) VALUES (... 如果不插入包括ccode 在内的所有 字段,则需要执行此操作,但是很难知道构造示例的结果是什么以及实际错误是什么,因为您是没有给出具体的错误信息。请具体一点。
  • 插入 tbl1 值 ('5055','Vangelyn De Castro') 插入 tbl2 值 ('1','01/26/16 08:40', '24:12:00' ,'来电')
  • 对不起,我忘了我单引号了 :)
  • 尝试insert into tbl1(customerId, customerName) VALUES ('5055','Vangelyn De Castro'),因为您不想为所有字段提供值。
  • "cannot convert into varbinary etc" 不是错误,请花时间编辑您的原始帖子并输入实际错误。

标签: sql database sql-server-2008


【解决方案1】:

我认为这只是一个基本的架构问题。

带有 ccode 的表 2 不应自动递增,因为 table1 拥有 ccode 的唯一值..

table2 ccode bigint, (not null)  -- that's it.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    • 2021-10-27
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 2018-06-29
    • 1970-01-01
    相关资源
    最近更新 更多