Ejemplo n.º 1
0
        public CreatePrimaryKey GenerateCreatePrimaryKeyStatement(Table t)
        {
            CreatePrimaryKey cpk = new CreatePrimaryKey();

            cpk.Table = t;
            return(cpk);
        }
        public string GenerateCreatePrimaryKeyScript(CreatePrimaryKey CreatePrimaryKeyStatement)
        {
            string TmpScript = "";

            if (CreatePrimaryKeyStatement.Table.PrimaryKeyName != String.Empty)
            {
                TmpScript += "alter table " + CreatePrimaryKeyStatement.Table.TableName + Environment.NewLine;
                TmpScript += "  add constraint " + CreatePrimaryKeyStatement.Table.PrimaryKeyName + Environment.NewLine;
                TmpScript += "  primary key (" + Environment.NewLine;
                foreach (string colName in CreatePrimaryKeyStatement.Table.PrimaryKeyColumns)
                {
                    //Column c = CreatePrimaryKeyStatement.Table.FindColumn(colName);
                    TmpScript += "    " + colName;
                    if (CreatePrimaryKeyStatement.Table.PrimaryKeyColumns.IndexOf(colName) != CreatePrimaryKeyStatement.Table.PrimaryKeyColumns.Count - 1)
                    {
                        TmpScript += "," + Environment.NewLine;
                    }
                    else
                    {
                        TmpScript += Environment.NewLine + "  )" + Environment.NewLine;
                    };
                }
            }
            return(TmpScript);
        }