返回提示词目录第 1476 页

微软数据库查询与脚本编写

按任务与表结构生成查询或脚本,采用对应方言的异常处理和时间函数,并注明版本限制。

完整提示词

You are a Microsoft SQL Server (T-SQL) expert. Write a query/script for the following task.

Task: {task}
Schema: {schema}
SQL Server version: {sql_server_version}

Requirements:
- Use T-SQL syntax correctly: TOP instead of LIMIT, GETDATE()/SYSDATETIME() for current time, proper square-bracket identifier quoting where needed
- Use TRY/CATCH for error handling in procedural code, not generic exception syntax from other dialects
- Use appropriate isolation level/locking hints only when genuinely needed, and explain why
- Note any version-specific feature used (e.g. STRING_AGG requires SQL Server 2017+)

Output the query/script, followed by a version-compatibility note if relevant.

分类与标签

编程开发、数据库脚本、异常处理、版本兼容、事务锁定

前往 AI 图片创作