Hello,I am creating the tables of SQL 2008 database.Most of the code is mine but 4 of the tables code came from another project.The way I and the other project creates tables and relationships is quite different:1) They use the following a lot: set quoted_identifier off go set ansi_nulls on go2) They define the constrains after the tables have been created using an Alter command.3) They always have: with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]) on [primary]I would like to know if I am doing something wrong ...Is there is a correct way to do everything the same way?EXAMPLESHow I create tables >use MyDB;gocreate table dbo.Tags( Id uniqueidentifier not null rowguidcol constraint PK_Tag primary key clustered, GroupId uniqueidentifier not null, constraint FK_Tags_Groups foreign key(GroupId) references Groups(Id) on delete cascade, [Name] nvarchar(40) not null,) -- Tagscreate table dbo.Posts( Id uniqueidentifier not null rowguidcol constraint PK_Post primary key clustered, Body nvarchar(max) not null, Created datetime not null, Excerpt nvarchar(max) not null, [File] varbinary(max) filestream default(0x), IPaper bit not null default 0, Published bit not null default 0, Title nvarchar(200) not null, Updated datetime not null) -- Posts create table dbo.PostsTags ( PostId uniqueidentifier not null, TagId uniqueidentifier not null, constraint PK_PostsTags primary key clustered (PostId, TagId), constraint FK_PostsTags_Posts foreign key(PostId) references Posts(Id) on delete cascade, constraint FK_PostsTags_Tags foreign key(TagId) references Tags(Id) on delete cascade ) -- PostsTags
How the other project creates tables >-- Applicationsset ansi_nulls ongoset quoted_identifier ongocreate table dbo.Applications( Id uniqueidentifier ROWGUIDCOL not null constraint DF_Application_Id default (newid()), [Name] nvarchar(256) not null, Description nvarchar(256) null, constraint PK_Application primary key clustered( Id ASC) with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]) on [primary]go-- Rolesset ansi_nulls ongoset quoted_identifier ongocreate table dbo.Roles( Id uniqueidentifier rowguidcol not null constraint DF_Role_Id default (newid()), [Name] nvarchar(50) not null, ApplicationId uniqueidentifier not null, constraint PK_Role primary key clustered ( Id asc) with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]) on [primary]go-- Usersset ansi_nulls ongoset quoted_identifier ongocreate table dbo.Users( Id uniqueidentifier rowguidcol not null constraint DF_User_Id default (newid()), ApplicationId uniqueidentifier not null, [Name] nvarchar(50) null, CreationDate datetime null, Username nvarchar(50) not null, constraint PK_User primary key clustered( Id asc) with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]) on [primary]go-- UsersRolesset ansi_nulls ongoset quoted_identifier ongocreate table dbo.UsersRoles( UserId uniqueidentifier not null, RoleId uniqueidentifier not null, constraint PK_UsersInRoles primary key clustered( UserId asc, RoleId asc) with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]) on [primary]go-- Profilesset ansi_nulls ongoset quoted_identifier ongocreate table dbo.Profiles( UserId uniqueidentifier rowguidcol not null constraint DF_Profile_UserId default (newid()), PropertyNames ntext null, PropertyValuesString ntext null, PropertyValuesBinary image null, LastUpdatedDate datetime not null, constraint PK_Profile primary key clustered ( UserId asc) with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary]) on [primary]go-- Rolesalter table dbo.Roles with check add constraint FK_Roles_Applications foreign key(ApplicationId) references dbo.Applications(Id)on update cascadeon delete cascadego-- Rolesalter table dbo.Roles check constraint FK_Roles_Applicationsgoalter table dbo.Users with check add constraint FK_Users_Applications foreign key(ApplicationId) references dbo.Applications(Id)go-- Usersalter table dbo.Users check constraint FK_Users_Applicationsgoalter table dbo.UsersRoles with check add constraint FK_UsersRoles_Roles foreign key(RoleId) references dbo.Roles(Id)on update cascadeon delete cascadego-- UsersRolesalter table dbo.UsersRoles check constraint FK_UsersRoles_Rolesgoalter table dbo.UsersRoles with check add constraint FK_UsersRoles_Users foreign key(UserId) references dbo.Users(Id)on update cascadeon delete cascadego-- UsersRolesalter table dbo.UsersRoles check constraint FK_UsersRoles_Usersgoalter table dbo.Profiles with check add constraint FK_Profiles_Users foreign key(UserId) references dbo.Users(Id)goalter table dbo.Profiles check constraint FK_Profiles_Users
Thank You,Miguel