本文介绍了如何在数据库组上运行查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Hii, i必须在几个数据库组相同的查询中运行创建表查询...我该怎么做.. 说例子我有7个数据库,其中有4个数据库,我想立即触发这个创建语句我怎么能这样做?Hii ,i have to run create table query on group of few databases same query ... How can i do that ..say example i have 7 databases among those there are 4 databases on which i want to fire this create statement at once how can i do that ??推荐答案DECLARE @DATABASE TABLE(ID INT IDENTITY(1, 1),NAME VARCHAR(100))INSERT INTO @DATABASE (NAME)SELECT 'Adventure'UNION ALLSELECT 'TESTDB'DECLARE @INDEX INT, @TOTAL INT, @DBNAME VARCHAR(100)SELECT @INDEX = 1SELECT @TOTAL = COUNT(*) FROM @DATABASEWHILE @INDEX <= @TOTALBEGINSELECT @DBNAME = NAMEFROM@DATABASEWHEREID = @INDEXSELECT 'USE ' + @DBNAME, @INDEXEXECUTE ('USE ' + @DBNAME)EXECUTE ('CREATE TABLE ' + @DBNAME + '..TEST1(NAME VARCHAR(100)) ')SET @INDEX = @INDEX + 1END 这篇关于如何在数据库组上运行查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 20:36