string CreateTableDefinition(ITableColumn col) { string dataType = string.Empty; if (String.IsNullOrWhiteSpace(col.ComputedColumn)) { dataType = OnlyNVarCharColumns ? $"nvarchar({DataTypeConverter.GetTypeLength(col.DataType)})" : col.DataType; } string identitySql = col.IsIdentity ? $"identity({col.IdentitySeed ?? 1},{col.IdentityIncrement ?? 1})" : string.Empty; string collationSql = !String.IsNullOrWhiteSpace(col.Collation) ? $"collate {col.Collation}" : string.Empty; string nullSql = string.Empty; if (String.IsNullOrWhiteSpace(col.ComputedColumn)) { nullSql = col.AllowNulls ? "NULL" : "NOT NULL"; } string primarySql = col.IsPrimaryKey ? $"constraint [pk_{TableWithoutSchema}_{col.Name}] primary key clustered ( [{col.Name}] asc )" : string.Empty; string defaultSql = string.Empty; if (!col.IsPrimaryKey) { defaultSql = col.DefaultValue != null?DefaultConstraintName(col.DefaultConstraintName) + $" default {SetQuotesIfString(col.DefaultValue)}" : string.Empty; } string computedColumnSql = !String.IsNullOrWhiteSpace(col.ComputedColumn) ? $"as {col.ComputedColumn}" : string.Empty; return($@"[{col.Name}] {dataType} {identitySql} {collationSql} {nullSql} {primarySql} {defaultSql} {computedColumnSql}"); }