对不起,如果我的问题不具体或者之前已经回答过.我试着寻找它并提出更好的方式,但这是最准确的方法.
我用Java开发了一个程序,我用以下方式在数据库中插入一个新行:
INSERT INTO table_name VALUES (?,?,?)
问题是我在程序的许多部分都有这个查询,现在我决定在我的表中添加第四列.我是否必须在程序中使用新问号更新EVERY SINGLE查询?如果我不这样做,它会崩溃.
在这些情况下,最好的方法是什么?
我有一个奇怪的问题,两个查询返回CRC32的不同哈希值与相同的字符串.
如果我跑:
SELECT 'http://mywebsite4.com/myvideos', CRC32('http://mywebsite4.com/myvideos');
返回的哈希值为3769016377.
如果我然后跑
INSERT INTO locations (full_url, full_url_hash) VALUES ('http://mywebsite4.com/myvideos', CRC32('http://mywebsite4.com/myvideos'))
插入的哈希值为2147483647.
我有什么明显的遗漏吗?据我所知,CRC32函数应该总是将相等的字符串散列为等于32位的整数,我不能在我的生活中弄清楚为什么它们在这种情况下是不同的.
谢谢!
我正在编辑一个使用MySQLi的脚本.我需要使用预准备语句将一些值插入到db中.
我的阵列形式为:
$insert = array('column1' => 'value1', 'column2' => 'value2', 'column3' => 'value3')
Run Code Online (Sandbox Code Playgroud)
到目前为止,我有这个,但我需要帮助bind_param.我在这里看过文档,call_user_func_array但是我不知道如何实现它.
$cols = array_keys($insert);
$query = "INSERT IGNORE INTO results (". implode(", ", $cols) .") VALUES (". implode(', ', array_fill(0, count($insert), '?')) .")";
$stmt = $mysqli->prepare($query);
$param = array_merge(array(str_repeat('s', count($insert))), array_values($insert));
call_user_func_array(array($stmt, 'bind_param'), $param);
$stmt->execute();
Run Code Online (Sandbox Code Playgroud)
PHP 5.4.17
我试图使用INSERT INTOSQL查询将新行插入我的数据库.我不确定我做错了什么,因为我不是更有经验的程序员.
我按下按钮时尝试将整数值1添加到问题类型列.我的主键自动递增,因此不应该是一个问题,因为所有其他列都可以为NULL.
INSERT INTO dbo.Questions (Question Type)
VALUES (1)
Run Code Online (Sandbox Code Playgroud)
当我按OK查询此查询时,会显示错误说明:
尝试创建参数化查询时发生错误:
函数参数列表出错:'Type'无法识别.不完整的参数或列表.无法解析查询文本.
这是我要添加到的表的代码:
CREATE TABLE [dbo].[Questions] (
[QuestionID] INT IDENTITY (1, 1) NOT NULL,
[Actual answer] NVARCHAR (50) NULL,
[Question Space] NVARCHAR (50) NULL,
[Question Type] INT NULL,
PRIMARY KEY CLUSTERED ([QuestionID] ASC)
);
Run Code Online (Sandbox Code Playgroud) 我遇到了问题.我正在开发一个ASP.net MVC应用程序来管理文件上传到数据库.没什么大不了的.但是每次执行我的SQL-Command时,他都告诉我需要先转换为VARBINARY.
这个问题在这里和互联网上被问到很多,但我仍然无法让它工作..
这就是我得到的:
SQL表:
DocID INT IDENTITY(1,1) NOT NULL,
DocName VARCHAR(512) NOT NULL,
DocData VARBINARY(max) NOT NULL,
ContentType NVARCHAR(100) NOT NULL,
ContentLength BIGINT NOT NULL,
InsertionDate DATETIME NOT NULL DEFAULT GETDATE(),
CONSTRAINT PK_DOC_STORE PRIMARY KEY NONCLUSTERED (DocID)
Run Code Online (Sandbox Code Playgroud)
使用BinaryReader将文件读取到byte [].
var reader = new BinaryReader(file.InputStream);
var data = reader.ReadBytes(file.ContentLength);
Run Code Online (Sandbox Code Playgroud)
INSERT INTO C#代码:
sqlConnection.Open();
var sqlCommand = new SqlCommand
(
"INSERT INTO DocStore VALUES ('@DocumentName', '@DocumentData', '@DocumentType', '@DocumentSize', '@DocumentDate')"
, sqlConnection
);
sqlCommand.Parameters.AddWithValue("@DocumentName", file.FileName);
sqlCommand.Parameters.AddWithValue("@DocumentData", data);
sqlCommand.Parameters.AddWithValue("@DocumentType", file.ContentType);
sqlCommand.Parameters.AddWithValue("@DocumentSize", file.ContentLength);
sqlCommand.Parameters.AddWithValue("@DocumentDate", …Run Code Online (Sandbox Code Playgroud) 我可以通过以下查询插入两行。如何在其中插入更多行?
insert into friend_name(
friend_id,
first_name,
middle_name,
last_name)
select
3,
'rich',
'mond',
'hill'
from dual
union all
select
4,
'monunica',
'bellu',
'cia'
from dual
Run Code Online (Sandbox Code Playgroud) 我想知道是否可以将列输入值重用作为另一个列值输入的默认值(如果留空)。我试图在DEFAULT代码之后简单地填充引用。
CREATE TABLE members (
name varchar(50) NOT NULL,
username varchar(50) DEFAULT name
);
INSERT INTO members (name) VALUES ('el duderino');
SELECT * FROM members;
Run Code Online (Sandbox Code Playgroud)
所需结果;
name | username
--------------+--------------
el duderino | el duderino
Run Code Online (Sandbox Code Playgroud)
insert语句运行但由于以下错误而无法建立表,因此找不到该表...
psql:website.sql:38:错误:无法在默认表达式中使用列引用
是否可以在一行的默认语句中引用值的名字?还是必须分阶段进行?任何帮助,不胜感激!
注意:我正在Cloud 9开发机器上运行Postgresql。
让我说我写一个像查询"INSERT INTO my_table (a,b) VALUES (1,2)".
从客户端传递查询到保存在磁盘上的时间内,MySQL内部会发生什么.
喜欢:
-> What all innodb objects(filesystem buffers/logs) affected?
-> What're the step the data has to pass through till it reaches on table space?
Run Code Online (Sandbox Code Playgroud)
换句话说,db的解剖学写道.
例如:
-> query being parsed by the parser
-> correct data page be loaded to innodb_buffer_pool
-> data being changed(dirty pages), and changes are logged to redo log buffer
-> entry on undo logs(rollback segment)
-> on commit, redo log buffer flushed to redo logfile
-> …Run Code Online (Sandbox Code Playgroud) Postgresql可以返回自动递增的值returning:
insert into table1 (id) values (null) returning id;
Run Code Online (Sandbox Code Playgroud)
我试图将返回的值插入另一个表:
insert into table2 (id) values ((insert into table1 (id) values (null) returning id)) returning id;
Run Code Online (Sandbox Code Playgroud)
但是这会into在嵌套之前抛出语法错误insert.
如何使用内部的返回值insert作为外部的值insert?
我有这个代码,将变量传递给函数并插入它.但是我收到了错误:
<cffunction name="insertSupplierPersonnel" output="false" access="public" returnType="struct">
<cfargument name="name" type="string" required="true" />
<cfargument name="email" type="string" required="false" default="" />
<cfargument name="office_phone" type="string" required="false" default="" />
<cfargument name="mobile_phone" type="string" required="false" default="" />
<cfargument name="designation" type="string" required="false" default="" />
<cfset var res = '' />
<cfquery datasource="#session.dsn_aset#" result="res">
INSERT INTO `supplier_personnel_incharge` (
`name`,
`email`,
`office_phone`,
`mobile_phone`,
`designation`
)
VALUES
(
cfargument.name,
cfargument.email,
cfargument.office_phone,
cfargument.mobile_phone,
cfargument.designation
) ;
</cfquery>
<cfreturn res />
</cffunction>
<cfset res = insertSupplierPersonnel(name='#form.personnel_name#', email='#form.personnel_email#', office_phone='#form.personnel_office_phone#', mobile_phone='#form.personnel_mobile_phone#', designation='#form.personnel_designation#') />
<cfdump var="#res#">
Run Code Online (Sandbox Code Playgroud)
我收到这个错误: …
sql-insert ×10
sql ×7
mysql ×5
c# ×2
postgresql ×2
sql-server ×2
coldfusion ×1
crc32 ×1
database ×1
function ×1
java ×1
mysqli ×1
oracle ×1
php ×1