?
Solved

Data from  SQL Server table and to Rename a table

Posted on 2002-05-26
10
Medium Priority
?
169 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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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