T-SQL 以 AAA 開頭的表格中的資料表名稱和相應的欄位名稱、欄位描述
2024-01-25
環境:Visual Studio 2022 + ASP.NET + WebForm + Web Application + C# + SQL Server 2019 + SQL Server Management Studio (SSMS) 19.x
********************************************************************************
T-SQL 以 AAA 開頭的表格中的資料表名稱
USE YourDatabaseName; SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'AAA%' ORDER BY TABLE_NAME; |
T-SQL 以 AAA 開頭的表格中的資料表名稱和相應的欄位名稱
USE YourDatabaseName; SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE 'AAA%' ORDER BY TABLE_NAME |
T-SQL 以 AAA 開頭的表格中的資料表名稱和相應的欄位名稱、欄位描述
SELECT t.name AS TableName, c.name AS ColumnName, ep.value AS ColumnDescription FROM sys.tables t JOIN sys.columns c ON t.object_id = c.object_id LEFT JOIN sys.extended_properties ep ON ep.major_id = t.object_id AND ep.minor_id = c.column_id AND ep.class_desc = 'OBJECT_OR_COLUMN' WHERE t.name LIKE 'AAA%' ORDER BY t.name, c.column_id; |
Default.aspx.cs
using System; using System.Data; using System.Data.SqlClient; namespace YourNamespace { public partial class YourPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string connectionString = "YourConnectionString"; // 替換為你的數據庫連接字符串 using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); // 查詢以AAA開頭的表名稱 string query = "USE YourDatabaseName; SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE 'AAA%';"; DataTable tableNames = new DataTable(); using (SqlCommand command = new SqlCommand(query, connection)) { using (SqlDataAdapter adapter = new SqlDataAdapter(command)) { adapter.Fill(tableNames); } } // 現在,tableNames包含以AAA開頭的表名稱 // 你可以在這裡進一步的處理,例如顯示或記錄這些表名稱。 } } } } |
(完)
相關
沒有留言:
張貼留言