Defining values while creating sql table

Hi friends  ,

This post and technique very new to me !!
It reduce lot of repeated work while using SQL queries with other technologies like (C#,Java,Perl etc)

Basically post refers to CREATE TABLE command of SQL

Example : Guess that , you want to calculate percentage of total marks ,get to particular students and store it table.
For that process , we need to create columns as id,fname,lname,totalMarks,Percentage etc.
Then we go for code ,we calculate from insert or select query or others.

I am trying through SQL Server 2008 R2...

Create table of  sample student table :
 
create table SampleTable
(
      id int identity(1,1),
      fname nvarchar(50),
      lname nvarchar(50),
      totalMarks float,
    passFlag as case when  totalMarks> =50 then 'Pass' else 'Fail' end persisted
)

Insert record and select query :

 
I hope you enjoy it..!! Feel free to suggest corrections .
 

Comments

Popular posts from this blog

File operations in C# (.net)

Add Serial no in crystal report without coding

How to get top " n " number of rows from table