In SSMS
, Azure Data Studio
, VS-Code
or Visual Studio
add the statement, change @TableName
to a desire table and ensure the database is selected.
Now imagine a developer with decent SQL skills was tasked with writing this statement, it might take an hour or more or even fail. Karen ask AI to generate the statement which took less than five seconds. So the point is, consider using GitHub Copilot
or another AI assistant to assist with writing any SQL and before using statements generated with AI in code test it with for SQL-Server SSMS (SQL-Server Management Studio).
Karen uses this to iterate all databases for a SQL-Server. Below is part of the code.
public static async Task<string> IterateDatabases()
{
StringBuilder builder = new();
List<IGrouping<string, DataContainer>> grouped = await DataOperations.ReadDataContainersGroupedAsync();
await FileOperations.WriteToFileAsync(grouped);
foreach (var groupItem in grouped.Where(groupItem => !Exclude.DatabaseNameList.Contains(groupItem.Key)))
{
builder.AppendLine($"{groupItem.Key}");
foreach (var item in groupItem)
{
if (Exclude.TableNameList.Contains(item.TableName))
{
continue;
}
builder.AppendLine($" {item.SchemaName}.{item.TableName}");
var columns = await DataOperations.ReadColumnDetailsForTableAsync(Utilities.ServerName(), groupItem.Key, item.TableName);
foreach (var column in columns)
{
builder.AppendLine($" {column.IsPrimaryKey.Primary(),-5}{column.Position,-5}{column.ColumnName,-30}{column.DataTypeFull,-15}{column.IsComputed.ToYesNo()}");
}
}
}
return builder.ToString();
}