title: How to set a function as a default value in SQL Server?
body: <p>I am in trouble please help.</p>
  
  <p>After searching for my question I decided to post here.</p>
  
  <p>Look at my code below and tell me if I can set default value as a function.</p>
  
  <p>What I want to do is to show first three characters of my first column's data which is <code>Product_Name</code>. </p>
  
  <p>For example my first column has a name <code>Xperia</code> and and I want its first three characters to be shown in the last column which I have created using alter code. </p>
  
  <p>I hope you understand what I say.</p>
  
  <pre><code>Xperia ----&gt;  Xpe
  </code></pre>
  
  <p>Code is :</p>
  
  <pre><code>alter table dummy
  add new_col varchar(250) default substring(first_column, 1, 3)
  </code></pre>
  
  <p>returns an error:</p>
  
  <blockquote>
    <p>Msg 128, Level 15, State 1, Line 2<br>
    The name "first_column" is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.</p>
  </blockquote>
  
  <p>However I can set <code>getdate()</code> function as a default value. </p>
  
  <p>Thanks</p>