Solved

Data from  SQL Server table and to Rename a table

Posted on 2002-05-26
10
166 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 70

Expert Comment

by:Éric Moreau
ID: 7036253
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
ID: 7036514
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 70

Expert Comment

by:Éric Moreau
ID: 7036774
inthedark is right. The SP to rename a table is sp_rename (and not sp_renameDB like I told).
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 17

Expert Comment

by:inthedark
ID: 7036784
emoreau very unlike you to be wrong about anything....
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7128815
Any progress?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7297390
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
ID: 7373220
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7373385
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7373404
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7373456
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

821 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