Solved

Data from  SQL Server table and to Rename a table

Posted on 2002-05-26
10
167 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

738 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