예제 #1
0
        /// <summary>
        /// Get some details for a database table. When doing this
        /// we can really drill down into the table details but
        /// here I kept it simple.
        ///
        /// When using this method and notice a table you believe
        /// had a Identity column comes up false then we need to check
        /// the ForeignKeyDetails list which is rigged up below but is
        /// not displayed. If you place a break-point in the next line
        /// below testKeys, hover over testKeys you will see id column(s)
        /// that can be auto-incrementing yet not set as IDENTITY columns.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmdColumnsForTable_Click(object sender, EventArgs e)
        {
            if (listBoxDatabaseNames.DataSource != null && listBoxTableNames.DataSource != null)
            {
                if (listBoxTableNames.FindString("(none)") == -1)
                {
                    var dbName = listBoxDatabaseNames.Text;
                    var tbName = listBoxTableNames.Text;

                    var columnDetails = serverOperations.GetColumnDetails(dbName, tbName);
                    List <ForeignKeysDetails> testKeys = serverOperations.TableKeys(dbName, tbName);

                    var schema = serverOperations.TableSchema(dbName, tbName);
                    var f      = new TableColumnForm(columnDetails);

                    string title = $"{dbName}.{schema}.{tbName}";

                    try
                    {
                        f.Text = title;
                        f.ShowDialog();
                    }
                    finally
                    {
                        f.Dispose();
                    }
                }
            }
        }
예제 #2
0
        public void ConstraintExists()
        {
            var ops = new SqlOperations(TestCatalog);

            SqlConnectionStringBuilder builder =
                new SqlConnectionStringBuilder(ops.ConnectionString);

            var catalog = builder.InitialCatalog;
            var smo     = new SmoOperations();


            var test = smo.TableKeys(catalog, "Gender");

            Assert.IsTrue(test.Count == 1,
                          "Expected one constraint");

            Assert.IsTrue(test.First().SchemaName == "FK_People_Gender",
                          "FK_People_Gender does not exists");

            Assert.IsTrue(test.First().TableName == "People",
                          "TableName should be People");
        }