Collections:
PHP MSSQL - Inserting Data into an Existing Table
PHP MSSQL - How To Insert Data into an Existing Table?
✍: Guest
If you want to insert a row of data into an existing table, you can use the INSERT INTO statement as shown in the following sample script:
<?php
$con = mssql_connect('LOCALHOST','sa','FYIcenter');
mssql_select_db('FyiCenterData', $con);
$sql = "INSERT INTO fyi_links (id, url) VALUES ("
. " 101, 'dev.fyicenter.com')";
$res = mssql_query($sql,$con);
if (!$res) {
print("SQL statement failed with error:\n");
print(" ".mssql_get_last_message()."\n");
} else {
print("One data row inserted.\n");
}
mssql_close($con);
?>
If you run this script, unfortunately, you will get an error:
SQL statement failed with error: The statement has been terminated.
So what is wrong with the statement? The error message does not give any details. You need to take this statement to SQL Server Management Studio to try it:
USE FyiCenterData GO INSERT INTO fyi_links (id, url) VALUES ( 101, 'dev.fyicenter.com') GO Msg 515, Level 16, State 2, Line 1 Cannot insert the value NULL into column 'notes', table 'FyiCenterData.dbo.fyi_links'; column does not allow nulls. INSERT fails. The statement has been terminated.
Now you know the problem is in the CREATE TABLE statement. See the next tutorial for details.
⇒ PHP MSSQL - Making Columns to Take NULL
⇐ PHP MSSQL - Dropping an Existing Table
⇑ SQL Server FAQs - PHP MSSQL Functions - Managing Tables and Data Rows
2024-03-07, 2225🔥, 0💬
Popular Posts:
How To Use "IF ... ELSE IF ..." Statement Structures in SQL Server Transact-SQL? "IF ... ELSE IF ......
How To Format DATETIME Values to Strings with the CONVERT() Function in SQL Server Transact-SQL? SQL...
How To List All Stored Procedures in the Current Database in SQL Server Transact-SQL? If you want to...
How To Drop a Stored Procedure in Oracle? If there is an existing stored procedure and you don't wan...
Can Date and Time Values Be Converted into Integers in SQL Server Transact-SQL? Can date and time va...