Wednesday, December 12, 2012

Create New table in Sql Server 2005 ,2008:

Use below query to create new table in sql server  (without primary key column,with primary key column ,case insensitive and accent sensitive):


Approach 1:

This is  a simple way to create a new table without  primary key  in sql server:

CREATE TABLE [dbo].[Tbluser](
      [name] [varchar](200)  NULL,
    [emailid] [varchar](100)  NULL
   )


Approach 2:

This is  a simple way to create a new table with primary key  in sql server:

CREATE TABLE [dbo].[Tbluser](
    [srno] [bigint] IDENTITY(1,1) NOT NULL,
    [name] [varchar](200)  NULL,
    [emailid] [varchar](100)  NULL
   )


Approach 3:

Create new table  with primary key and with no case sensitive column so 'XYZ' can equal to 'abc',  but it will be accent sensitive so ü' does not equal 'u' but .

CREATE TABLE [dbo].[Tbluser](
    [srno] [bigint] IDENTITY(1,1) NOT NULL,
    [name] [varchar](200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [emailid] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [contact_no] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [password] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [joining_date] [datetime] NULL,
    [isvalid] [bit] NULL CONSTRAINT [DF_Tbluser_isvalid]  DEFAULT ((0)),
    [login_count] [int] NULL CONSTRAINT [DF_Tbluser_login_count]  DEFAULT ((0))
) ON [PRIMARY]

In above query srno is primary key and its value is always set as not null as primary key cannot have value .Identity property in sql server is used to get auto increment of the column on each new row addition.

SQL_Latin1_General_CP1_CI_AS meaning is given below:
  • Latin1:latin1 makes the server treat strings using charset latin 1,
     basically ascii 
  • CI: no case sensitive
  • AS: accent sensitive

 

No comments:

Post a Comment