Solved

Data from  SQL Server table and to Rename a table

Posted on 2002-05-26
10
163 Views
Last Modified: 2010-05-02
Hi

Can any one give me the complete code to rename a table in SQL Server and also to read data from a table in SQL server where there are duplicates  say
RollNo , subject  , Studentmarks ,
001    ,  maths    ,100
001    ,   science, 150
0
Comment
Question by:Richards
  • 6
  • 2
  • 2
10 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
1. sp_renameDB 'from', 'to'


2. select *
from YourTable
where RollNo in (
   Select RollNo
   FROM YourTable
   GROUP BY RollNo
   HAVING COUNT(*) > 1)
0
 
LVL 17

Accepted Solution

by:
inthedark earned 100 total points
Comment Utility
Here is a rename function:

Function RenameTableOK(CN As ADODB.Connection, Oldname As String, NewName As String)

' Renames a SQL Server Table
' Example:
'Dim Ok
'Dim CN As ADODB.Connection
'Set CN = New ADODB.Connection
'CN.ConnectionString = "...."
'CN.Open
'Ok = ADO.ReanameTableOK(CN, "MyOldTableName", "MyNewTanleName")

Dim SQL As String
Dim Ok

SQL = "EXEC sp_rename '" + Oldname + "', '" + NewName + "'"

On Error Resume Next
CN.Execute SQL
If Err.Number <> 0 Then
    RenameTableOK = False
Else
    RenameTableOK = True
End If

End Function
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
inthedark is right. The SP to rename a table is sp_rename (and not sp_renameDB like I told).
0
 
LVL 17

Expert Comment

by:inthedark
Comment Utility
emoreau very unlike you to be wrong about anything....
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
Any progress?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
This question appears to be abandoned. A question regarding it will be left in the CleanUp
area; if you have any comment about the question, please leave it here.

Unless there is objection or further activity, one of the moderators will be asked to accept the comment
of <emoreau>.

The link to the Community Support area is:
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

DO NOT ACCEPT THIS COMMENT AS AN ANSWER.
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
0
 
LVL 5

Expert Comment

by:Netminder
Comment Utility
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now