Mssql Cannot Update Identity Column

MS SQL Table


CREATE TABLE [dbo].[name](

   [id] [int] IDENTITY(1,1) NOT NULL,

   [name] [nvarchar](50) NOT NULL,

   CONSTRAINT [PK_name] PRIMARY KEY CLUSTERED



Model:




class Name extends CActiveRecord

{

	public static function model($className=__CLASS__)

	{

		return parent::model($className);

	}


	public function tableName()

	{

		return 'WebSite.dbo.name';

	}


	public function rules()

	{

		return array(

			array('name', 'required'),

			array('id', 'numerical', 'integerOnly'=>true),

			array('id, name', 'safe', 'on'=>'search'),

		);

	}


	public function relations()

	{

		return array(

		);

	}


	public function attributeLabels()

	{

		return array(

			'id' => 'ID',

			'name' => 'Name',

		);

	}


}



Controller update:




public function actionUpdate($id)

	{

		$model=$this->loadModel($id);


		if(isset($_POST['Name']))

		{

			$model->attributes=$_POST['Name'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->id));

		}


		$this->render('update',array(

			'model'=>$model,

		));

	}



_form.php




echo $form->textField($model,'name');

echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save');



I got:

Yii create this sql to Mssql:




UPDATE [WebSite].[dbo].[name] SET [id]=:yp0,

[name]=:yp1 WHERE [WebSite].[dbo].[name].[id]=2



I don’t set “id” field at the form. Why Yii set [id]=:yp0 in sql?

up