Wednesday, January 7, 2009

creating a table



Now you know how to create a database here is an example of creating a table.


USE [test]
GO
/****** Object: Table [dbo].[Audit] ******/SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[test]( [id] [int] IDENTITY(1,1) NOT NULL, [tracename] [nvarchar](100) NULL, [enable] [int] NULL) ON [PRIMARY]

If NULL is specified, the field is allowed to be left empty. If NOT NULL is specified, the field must be given a value. In the absence of either a NULL or NOT NULL, NULL is assumed.

The above query will create the table student with fields ID and Name.PRIMARY KEY : A PRIMARY KEY is a field in a table that uniquely identifies a record. This attribute is used to define the field name to create a primary key.

PRIMARY KEY(id)

No comments:

Post a Comment