I have a database on my student server, I need to go to my university if I want to access the database properties using the SQL server DBMS, it is a pain. I want to know if I can change the identity specification by using SQL on a specific table? I cannot insert to a table as this is not selected to yes, I want to be able to make these changes from home can I do this?
I was researching how to access tables and change some properties, and came across something like this:
Set IDENTITY_INSERT TableName ON
I want to be able to do this using a php script and some SQL, like this:
$query = "IDENTITY_INSERT customers ON ";
$result = sqlsrv_query( $conn, $query, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
if( $result === false)
{
echo "Error in query preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
else
{
echo'worked';
}
will this work?
Here is my rough attempt at doing this:
<?php
$serverName = "servername";
$connectionInfo = array("UID" => "username", "PWD" => "password", "Database"=>"database");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false ) // note the format of ‘equals’
{
echo "Could not connect.\n";
die( print_r( sqlsrv_errors(), true));
}
$query = "SET IDENTITY_INSERT customers ON ";
$result = sqlsrv_query( $conn, $query, array(), array( "Scrollable" => SQLSRV_CURSOR_KEYSET ));
if( $result === false)
{
echo "Error in query preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
else
{
echo'worked';
}
?>
Thank you.