How To Change The Database Context And Modify Tables?
Oct 4, 2007
I have 30+ databases in sql 2000.
I want to dynalically loop though each of the databases and alter a column named 'EmpName' for all the 'Employees' tables in that database.
Here is my attempt.use Master
go
declare @SQLString Nvarchar(1000)
declare @DBName Nvarchar(100)
declare @SQL2 NVARCHAR(1000)declare @TABLE_NAME NVarchar(100)
DECLARE curDB CURSOR LOCAL FORWARD_ONLY STATIC FOR
SELECT name FROM sysdatabases
OPEN curDB
FETCH NEXT FROM curDB INTO @dbname
While @@FETCH_STATUS=0
Begin
SET @SQL2 = 'USE ' + @DBNAME + ' ALTER TABLE ' + @TABLE_NAME + ' MODIFY EmpName varchar(100)'
from information_schema.tables where table_type = 'BASE TABLE' and table_name like '%Employees%' PRINT @SQL2
EXECUTE SP_EXECUTESQL @SQL2
fetch next from curDB into @DBName
end
Close curDB
End
When i execute the above script in master, it says 'Query executed successfully' but when i see the all the Employees table in each of the database, the required change is not made.
Can anybody explain this or give an alternate solution?
View 2 Replies
ADVERTISEMENT
Oct 4, 2007
I am using Sql Server 2000.
I have about 25+ databases . I want to run a series of commands on each database... how can I change the database context - the current database - dynamically in a loop...
something like this below:
declare @SQLString Nvarchar(1000)
declare @DBName Nvarchar(100)
declare @SQL2 NVARCHAR(1000)
declare @TABLE_NAME NVarchar(100)
While @@FETCH_STATUS=0
Begin
SET @SQL2 = 'USE ' + @DB_NAME + ';GO;ALTER TABLE ' + @TABLE_NAME + ' MODIFY Name varchar(100)'
PRINT @SQL2
EXECUTE SP_EXECUTESQL @SQL2
End
I am getting an error when i run the above commands:
Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'GO'
Can someone give me the correct solution?
View 4 Replies
View Related
Apr 28, 2015
USE master
Declare @db as nvarchar(258) = quotename (N'tempdb')
EXEC (N'USE' + @db + N'; EXEC(''SELECT DB_NAME();'');');
View 5 Replies
View Related
Jun 18, 2006
Hi There
I am trying to loop through databases to gather information.
However if i loop though datbases in a cursor, by using a select from sysdatabases, once i am in the cursor and SET @Sql = 'use ' + DBName and EXEC(SQL), the database context never changes from the one the cursor is executing in.
Is there a way to loop through database contexts and execute sql ?
Thanx
View 3 Replies
View Related
Feb 7, 2007
Hi All
i am very new to SQL CLR,
I create create an sample stored Procedure and registed the assembly and execute the SP in the query window , its working fine. But my doubt was -
1) In the SQLConnection object ,its like ("context connection=true") What is the use of this string and can i change this string to like this "Data Source=SystemNameSQLExpress;Initial Catalog=SampleDB;Integrated Security=True"?
is it possible to change the connection in the SQLConnection constructor with any databse connection
2) Is there any possobility to add configuration file in SQL Server project?
Please any one help me to know ... Thanks in Advance...
View 7 Replies
View Related
Jun 6, 2008
Hi,
it has to do with my unfamiliarity with creating users and dbo privileges. I'm trying to grant access to an outside vendor to import their latest version of a database. I set them up with a user account that had db_owner privileges, however when they ran the dts process it copied all the data as new tables rather than overwriting the existing tables and the new tables were all associated with the user is created instead of dbo user. What do I need to do to facilitate this process?
View 1 Replies
View Related
Aug 3, 2006
I am trying to change owner of all tables in a database. How can I doit?
View 1 Replies
View Related
Jul 22, 2015
How to Change Order of Column In Database Tables
View 10 Replies
View Related
Sep 28, 2007
Hi all,
I am new to SQL Server databases.Here i have a question that can we modify system tables in SQL Server 2000?
Any help would be helpful to me.....:-)
Thanks,
Narsi
View 6 Replies
View Related
May 22, 2006
Getting this message on my event log:
.NET Runtime Optimization Service (clr_optimization_v2.0.50727_32) - Failed to compile: Microsoft.ReportingServices.QueryDesigners, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91 . Error code = 0x80070002
View 1 Replies
View Related
Feb 7, 2008
What do I have to do in order to create a user that can alter and modify some/all tables?
Thank you.
View 2 Replies
View Related
Jul 30, 2007
I’m trying to create a modified catalog tree out from two tables in sql
The catalog is created from two tables.
Table 1 has the lowest level and is showing the connection with the item and the lowest ItemGroup. It also shows the connection with the MainCatalog
MainCatalogId, ItemGroupId, ItemId
Example data:
(sorry for the tabs that won't work)
MainCatalogIdItemGroupIdItemId
715063823
715073824
715093825
715093826
The catalog structure is in table 2. Here are the connections between the different
ItemGroupId, ParentId
Example data:
ItemGroupIdParentId
15061365
15071365
15091364
13641066
13651066
1066NULL
To be able to use create the tree structure and not getting the result set to big, I need it to look something like this:
ItemGroupIdItemIdLevel 2 level 3Level4
1506 3823136510667
1507 3824136510667
1509 3825136410667
1509 3826136410667
I have tried many ways, but I’m not getting the result I want.
Hope this was understandable, and that someone has an idea if this is manageable
Thanks :)
View 1 Replies
View Related
May 21, 2008
I get the error below when trying to modify a table or colum with MSSMS. I can expad out the tree and look at the columns, but I can't change them, view the data in them, or create new ones.
__________________________________________________________________________________________________________________________________
TITLE: Microsoft SQL Server Management Studio
------------------------------
Class does not support aggregation (or class object is remote) (Exception from HRESULT: 0x80040110 (CLASS_E_NOAGGREGATION)) (Microsoft.SqlServer.SqlTools.VSIntegration)
I resintallelled .NET Framework, recommended from another post. I am using .NET 3.5 BETA Frame work, ans SQL Server 2005 V 9.00.139.00
View 2 Replies
View Related
Apr 29, 2003
Hi,
I am trying to create a block of sql statements that will read the sysdatabases table, and store the value of the database in a variable.
I want to use a cursor to step through all these databases (excep of course the control databases).
For each of the databases I want to run a backup log followed by dbcc shrinkfile. For dbcc shrinkfile, I need to change the database context.
What I am finding is that I cannot use the variable to hold the database name.
here is the code
-------------------------
SET NOCOUNT ON
DECLARE @db_name varchar(100)
DECLARE @db_filename varchar(100)
DECLARE list_dbs Cursor
FOR select [name] from master..sysdatabases
OPEN list_dbs
FETCH NEXT FROM list_dbs into @db_name
WHILE @@FETCH_STATUS = 0
BEGIN
select name = @db_filename from @db_name..sysfiles
backup log @db_name with no_log
use @db_name
dbcc shrinkfile (@db_filename, 25)
FETCH NEXT FROM list_dbs into @db_name
END
CLOSE list_dbs
DEALLOCATE list_dbs
-----------------------
I get a syntax error where ever the @db_name is used (on the select and on the use).
Any suggestions?
Thanks,
Jim
View 7 Replies
View Related
May 14, 2007
Hi, all experts here,
Thank you very much for your kind attention.
I am trying to modify the files path (primary file, log file) of databases, but it looks like I am not able to mofidy their files path directly from the database property dialogue? Would please any experts here give me some ideas on what else can I try to figure it out? Thanks a lot in advance and I am looking forward to hearing from you shortly.
With best regards,
Yours sincerely,
View 5 Replies
View Related
Mar 15, 2001
Hi all,
I have an application that executes the USE command as it's first order of businees with the database. According to the SQL Books On-line, all USE commands will result in the following message being generated:
Error 5701
Severity Level 10
Message Text:
Changed database context to '%.*ls'.
However, my application has never reported this message, execept for at one customer site. I cannot figure out why at this one particular site, the customer is seeing this message each time the application starts. Once they ok the message, everything else with the application is fine, but it is a nuisance for them (gotta love customers!).
Any ideas why this would start happening?
View 1 Replies
View Related
Feb 6, 2008
In reading Has_Perms_By_Name documentation in BOL, it appears that using a three-part name will make no assumption on the database context. However, when I run the code below, I get results that are database context sensitive.
Code Snippet
USE [master];
print has_perms_by_name('master.sys.sysusers', 'object', 'select')
print has_perms_by_name('msdb.sys.sysusers', 'object', 'select')
print has_perms_by_name('AdventureWorks.sys.sysusers', 'object', 'select')
print ''
USE [msdb];
print has_perms_by_name('master.sys.sysusers', 'object', 'select')
print has_perms_by_name('msdb.sys.sysusers', 'object', 'select')
print has_perms_by_name('AdventureWorks.sys.sysusers', 'object', 'select')
print ''
USE [AdventureWorks];
print has_perms_by_name('master.sys.sysusers', 'object', 'select')
print has_perms_by_name('msdb.sys.sysusers', 'object', 'select')
print has_perms_by_name('AdventureWorks.sys.sysusers', 'object', 'select')
The results are:
1
1
1
1
1
1
0
0
0
I created a login called 'temp' and added a user for this login in the AdventureWords database. I then added a securable for sys.sysusers for this user in the Adventureworks database. I then selected the "Deny" checkbox for the Select permission. I connected as temp and ran the T-SQL above.
It appears that the database name is being ignored when included in the name of the securable. What am I missing? Is this a bug?
My version: Standard SQL Server 2005 9.0.3054 on Windows 2003 R2 SP2 (3790).
Thanks,
Randy
View 1 Replies
View Related
Jan 13, 2005
I am in a bind here..
I am getting the message (after do any sort of query) Database context changed to <dbname> I am using PHP as the p language.
Does anyone have any clue on why it is doing that..
Recently my host upgraded there PHP to version 4.3.10 and before the upgrade the queries were working fine.
Im on a windows server that runs PHP and im using a MSSQL database.
I've checked the bug reports on PHP and didn't come up with anything as well as googling the error..
IF you have any insite on this problem please let me know.. It may be a stupid error that I am overlooking on my part.
Thanks in advance
View 1 Replies
View Related
Feb 27, 2007
SImon writes "I'm unable to take a user database offline because there are system process using it and I can't identify or kill the system processes"
View 1 Replies
View Related
May 21, 2008
hi there,
After replicating a database, the stored procedures in that same database are not able to edit by other users than service account (sys admin users), When the normal users try to edit any of the stored procedures, sql server 2005 is throwing the following error...
Msg 21050, Level 16, State 1, Procedure sp_MSmerge_ddldispatcher, Line 12Only members of the sysadmin fixed server role or db_owner fixed database role can perform this operation. Contact an administrator with sufficient permissions to perform this operation.
any suggessions are most welcome.
by
CHINNASAMY
View 1 Replies
View Related
Aug 14, 2007
I have database in the database there are a few users that no one is used. When I try to drop thpse users I got next error message:
"The database principal is set as the execution context of one or more procedures, functions, or event notifications and cannot be dropped." (Msg 15136)
Indeed, I think that those users have execute rights on store procedures.
How do I find for wich procedures or other database objects those users have grants?
How do I delete them from database (and maybe from logins of the server)?
How can I see what grants a user has?
How can I see what grants does STP has?
View 10 Replies
View Related
Jun 23, 2006
I know sysprocesses has the information, but I can't seem to find how this is done using the dmv's. sessions doesn have a db context, and requests is only active while activity is occurring.
Thanks!
View 4 Replies
View Related
Jul 13, 2007
Please give me advise ครับ
View 1 Replies
View Related
Jun 2, 2006
Hi,
I have a MSSQL database running in a Microsoft cluster. I was working on troubleshooting for another SAP problem when they suggested I change the setting using hte SQL Server Client Network Utility to 'named pipes' from 'tcp/ip'. Every since, despite changing it back I'm unable to start the database in the cluster.
I'm kind of a newbie at this so I'd really appreciate any help in getting this database up and running.
Here is the error message from the event log:
sqsrvres] checkODBCConnectError: sqlstate = HY000; native error = 0; message = [Microsoft][ODBC SQL Server Driver]Cannot generate SSPI context
View 2 Replies
View Related
Dec 4, 2003
Hi,
On Administrator session, I have created an CUSTOMER MSDE database. That's OK.
On user session, I want to access on my database CUSTOMER but I have on error : "Unable to connect to the database". And, in French : "Echec de la connexion de l'utilisateur Machine_Name/User_Name".
What is the error ? I don't know what to do any more.
How to give right to the user ? Have you an idea ?
Thank's.
Patrice A. BONNEFOY.
View 2 Replies
View Related
Feb 20, 2006
Windows XP
SQL Expresss 2005
SQL Express 2005 Manager
I simply want to edit and data I have in a database that I made with Express Manager. This worked before .Net 2.0. Now, I have the table displayed as a datagrid with an "edit" pushbutton associated with each row in the database table. When I click on the "edit" pushbutton to edit a specific row in the database table, instead of posting me to a page where the chosen row is editable, I am posted back to the same page without the chosen row availible to be edited.
What am I doing wrong? How can I fix this? I am totally new to this so any help would be appreciated.
Cheers!
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" EnableEventValidation="false" %><%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls" Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %><MM:DataSet id="dsParts"runat="Server"IsStoredProcedure="false"ConnectionString='<%# System.Configuration.ConfigurationSettings.AppSettings["MM_CONNECTION_STRING_PartsAreUs"] %>'DatabaseType='<%# System.Configuration.ConfigurationSettings.AppSettings["MM_CONNECTION_DATABASETYPE_PartsAreUs"] %>'CommandText='<%# "SELECT * FROM dbo.Parts" %>'Debug="true"> <EditOps> <EditOpsTable Name="dbo.Parts" /> <Parameter Name="Name" Type="VarChar" /> <Parameter Name="Description" Type="NVarChar" /> <Parameter Name="Price" Type="Money" /> <Parameter Name="PartID" Type="Int" IsPrimary="true" /> </EditOps></MM:DataSet><MM:PageBind runat="server" PostBackBind="true" /><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><title>Untitled Document</title></head><body><form runat="server"> <asp:DataGrid id="dgParts" runat="server" AllowSorting="False" AutoGenerateColumns="false" CellPadding="3" CellSpacing="0" ShowFooter="false" ShowHeader="true" DataSource="<%# dsParts.DefaultView %>" PagerStyle-Mode="NextPrev" DataKeyField="PartID" onCancelCommand="dsParts.OnDataGridCancel" onEditCommand="dsParts.OnDataGridEdit" onUpdateCommand="dsParts.OnDataGridUpdate" onItemDataBound="dsParts.OnDataGridItemDataBound" > <HeaderStyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="smaller" /> <ItemStyle BackColor="#F2F2F2" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" /> <AlternatingItemStyle BackColor="#E5E5E5" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" /> <FooterStyle HorizontalAlign="center" BackColor="#E8EBFD" ForeColor="#3D3DB6" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Bold="true" Font-Size="smaller" /> <PagerStyle BackColor="white" Font-Name="Verdana, Arial, Helvetica, sans-serif" Font-Size="smaller" /> <Columns> <asp:EditCommandColumn ButtonType="PushButton" CancelText="Cancel" EditText="Edit" HeaderText="Edit" UpdateText="Update" Visible="True"/> <asp:BoundColumn DataField="PartID" HeaderText="PartID" ReadOnly="true" Visible="True"/> <asp:BoundColumn DataField="Name" HeaderText="Name" ReadOnly="false" Visible="True"/> <asp:BoundColumn DataField="Description" HeaderText="Description" ReadOnly="false" Visible="True"/> <asp:BoundColumn DataField="Price" HeaderText="Price" ReadOnly="false" Visible="True"/> </Columns> </asp:DataGrid></form></body></html>
View 3 Replies
View Related
Mar 1, 2006
I have replaced the installation of MSDE 1.0 with MSDE 2000.
Prior to installation of MSDE 2000, I can perform the activities of all
database role. Now, I can only add, change and delete data - no
more database design.
What should I do to regain database design permission?
I'm using "sa" user with blank password when I login to MS Access Project.
View 5 Replies
View Related
Jan 20, 2008
Hello, I have gone to work for a new company and I have seen this company is running out of drive space on a daily basis. The DBA before me created huge databases. For example we have a database that it's created size is 103 GB. Only about 52 GB is ever needed. I know you can resize the tempdb but how about user databases? I have never tried this. Can this be done for a user database?
For tempdb
Start SQL from cmd line sqlserver -c -f -s%instance_name%
alter databse tempdb modify file
(name='tempdev',size=150)
View 3 Replies
View Related
Jun 16, 2007
I have a login that is mapped to a Windows sysadmin account. I used it to login to Sql Server 2005. I then created a database called Freedom. I then added a Windows login and user called FreedomAdmin, with Freedom set as the default database. When I login in to Windows using FreedomAdmin and then try to login in to Sql Server 2005, I get the following error:
The server principal "FREEDOM1FreedomAdmin" is unable to access the database "master" under the current security context.
If the default database for FreedomAdmin is Freedom (and it is - I checked from my sysadmin login account), why can't I login. Must I give FreedomAdmin permissions to master?
View 6 Replies
View Related
Feb 7, 2008
I have a restriced user on SQL Server that is only permitted to creat a new database and manage it only. All other database are hidden to that user.
when that user login to SQL Server and create a database and try to change the default folder path for data and log files, gets an error,
The Server principal "User" is not able to access the database "model" under the current security context. (MSSQL Server, Error: 916)
Any idea???
Thanks,
View 7 Replies
View Related
May 23, 2007
SQL2005 on winserver 2003. I have a view in Xdb that accesses tables in 2 different databases (Xdb and Ydb) on the same server. I have mixed mode security. I have a SQL user (XYuser) that has read access to all tables and views on both databases, yet when I try to access the view using a C# windows application I get the following error:
The server principal "XYuser" is not able to access the database "Ydb" under the current security context
This same scenario works under SQL 2000. I looked through the postings and tried to set TRUSTWORTHY ON on both databases but that didn't help. I can access any other views or tables on the SQL 2005 server, just not the one that joins the tables cross databases. Any help is much appreciated... john
View 17 Replies
View Related
Mar 2, 2008
Hi try to connect with driver {SQL Sever Client} but i can't
I'm have SQL Server 2005 Express SP2
Error connecting to the ODBC server:[Microsoft][SQL Native Client][SQL Server] Changed database context to..
Please Help me
Thanks
View 10 Replies
View Related
May 1, 2007
Hi guys. I created a database "MyDatabase" using an AD Account "user01" which is a member of a domain group "GroupA". I have created a login in my SQL Server 2005 for this AD group. I have also added the said login as a user of my database. I created other AD users and put them in the same group. When I try to access the database using the other users, I get this message
The server principal "MyDomainuser02" is not able to access the database "MyDatabase" under the current security context.
This KB tells me that my situation is triggered by the first case in which the owner of the database is windows authenticated. I have already set the database to be TRUSTWORTHY. I haven't tried CERTIFICATES though. I believe I haven't done anything complex to warrant this solution.
I'm really lost with the myriads of principals and securables that SQL2005 has. All I want is just to execute a certain set of stored procedures. I can't do this because I can't even execute "USE MyDatabase". What are the permissions I need to give to "GroupA" ?
View 5 Replies
View Related