Rename the existing table with date suffix

Hi,
I'm trying to rename a table with date suffix at the end of the table name, and drop the date suffix table which is greater than 7 days. for that I have the below sql, I have not included the drop syntax in this.
I'm not able to rename with the date suffix in the below sql, syntax error at '+'  
DECLARE
@TPartitionDate date
IF EXISTS (SELECT * FROM sysobjects WHERE Name = 'IIS_4')
BEGIN
SELECT
@TPartitionDate = MAX(PartitionDate)
FROM PartitionLog (NOLOCK)
EXEC sp_rename 'IIS_4','IIS_4_'+ @TPartitionDate
END

create table Test(sno int)
DECLARE
@TPartitionDate date = getdate()
declare @a varchar(200)
IF EXISTS (SELECT * FROM sysobjects WHERE Name = 'Test')
BEGIN
select @a='TEST_'+ cast(@TPartitionDate as varchar(10))
EXEC sp_rename 'TEST',@a
END
drop table [test_2015-04-23]
Hope it Helps!!

Similar Messages

  • How add primary key constraint to already existing table with data

    I want apply primary key constraint to already existing table with data
    is there any command or way to do

    Alternatively, assuming you want to ensure uniqueness in your primary key column you can do this:
    alter table <table name> add constraint <cons name> primary key (col1,col2) exceptions into <exception_table>
    If the altter table statement fails this will populate the EXCEPTIONS table with the rows that contain duplicate values for (col1,col2).
    You will need to run (or get a DBA to run) a script called UTLEXCPT.SQL (which will be in the $ORACLE_HOME/rdbms/admin directory) if you don't already have an EXCEPTIONS table.
    Cheers, APC

  • Creating Partitions in Existing tables with Data

    Hello everyone,
    I want to know what the best way of creating partitions, in tables having data, is .. ???
    thanks
    Rossy Rocs

    There are two ways :
    1a Create a new Partitioned Table
    1b Copy data from the existing table to the new table
    1c Create Indexes
    1d Rename old table
    1e Rename new table
    OR
    2 Use DBMS_REDEFINITION
    See
    http://www.oracle-base.com/articles/misc/PartitioningAnExistingTable.php
    Hemant K Chitale

  • Partitioning an Existing Table with data

    Hi All,
    I am few tables with data, I need to Partition the table without affecting existing table values is it possible?.
    if yes then Please suggest me some ideas to archive that..
    Thanks & Regards
    Sami

    Hi All,
    I Need to partition for existing table with 1 million records
    1. First partition should be created for 6 months
    2.Second partition should created for 1 year.
    3.So as of now we have 6 months Data in production + another 6 months data in First partition + another 1 year data in Second partition.
    4.More than 2 year’s data’s should be moved other partition or archived.
    kindly provide your valuabe suggestion.
    Thanks & Regards
    Sami

  • Partition an Existing Table with Data

    We have a table that is approx. 23Gb with 90 million rows. We need to partition it. What is the fastest or most efficient way to accomplish this? Oracle 10.2.0.4.

    user1175547 wrote:
    We have a table that is approx. 23Gb with 90 million rows. We need to partition it. What is the fastest or most efficient way to accomplish this? Oracle 10.2.0.4.you can use DBMS_REDEFINITION, also exchange partition is also a good solution :)
    http://www.oracle-base.com/articles/misc/PartitioningAnExistingTableUsingExchangePartition.php

  • How to create a table from an existing table with new column

    Hi !
    Please help me.
    I want to create a table from an existing table with data and add two new column to the new table.
    What will be the syntax?

    craete table new_table as select a.*, 'somevalue' new_col1, 'somevalue'
    new_col2 from old_table a;Also there is a pitfall - newly created table will accept column type and precision from the select statement, so further you can be needed to modify columns
    if you want to have VARCHAR2 instead of CHAR for example:
    SQL> create table new_dept as select dept.*, 'New data' new_col from dept;
    Table created.
    SQL> desc new_dept
    Name                                      Null?    Type
    DEPTNO                                             NUMBER(2)
    DNAME                                              VARCHAR2(14)
    LOC                                                VARCHAR2(13)
    NEW_COL                                            CHAR(8)
    SQL> alter table new_dept modify (new_col varchar2(8));
    Table altered.
    SQL> desc new_dept
    Name                                      Null?    Type
    DEPTNO                                             NUMBER(2)
    DNAME                                              VARCHAR2(14)
    LOC                                                VARCHAR2(13)
    NEW_COL                                            VARCHAR2(8)Rgds.
    Didn't see michael's post - it reflects the fix for this problem using CAST.
    Message was edited by:
    dnikiforov

  • How to pass internal table with data in ABAP OO

    Hi experts ,
    Here is the problem...
    I create a screen 100 and use the internal table to get data from database, and then press the button on screen 100 , it will call screen 200.
    I use ABAP OO code in screen 200, and i want to keep the internal table with data that i get from the sceen 100 parts, but it seems that it just supports to create a new internal table and get data from database in ABAP OO. That means i need to create a new table to save the data in internal table ? Or there is any other solution something like exporting or memory id ...
    ps . the internal table in screen 100 is declared in global area, the beginning of the code.
    Please give me some advice, thanks a lot!
    Regards ,
    Claire

    I have already know how to do, here is my code:
    METHODS fill_tree importing itab2 like itab1.
    CALL METHOD: me->fill_tree exporting itab2 = itab1.
    In METHOD fill_tree,
    declare
    data: itab3 TYPE STANDARD TABLE OF itab,
    itab3[] = itab1[].
    It is useful to me, thanks a lot.

  • What is the best wayt to copy tables with data from development to Prod?

    Dear all,
    We have Oracle tables with data in a development server, I would like to know if there is any ‘easy’ and ‘direct’ way to copy them to the production server.
    As I think import and export would be the best way. Any other althernatives?
    Thanks.

    There are a number of methods you could use.
    <ul><li>
    Export and import would work or their 10g+ equivalents data pump. </li>
    <li>You could create a database link between the 2 databases and use SQL*Plus copy to transfer data on a table by table basis (probably quite laborious unless there's only a few tables). </li>
    <li>You could use transportable tablespaces (there are some restirctions - check the documentation http://download.oracle.com/docs/cd/E11882_01/server.112/e10595/tspaces013.htm#sthref1632) </li>
    <li>You could use RMAN to clone the development database (assuming the prod database hasn't been used yet and that there's nothing in it you need to keep).</li>
    <li>You could create the prod database as a standby copy of the dev database </li>
    </ul>
    Using transportable tablespaces would be much faster than using data pump or import/export depending on how much data there is.

  • Sample report for filling the database table with test data .

    Hi ,
    Can anyone provide me sample report for filling the database table with test data ?
    Thanks ,
    Abhi.

    hi
    the code
    data : itab type table of Z6731_DEPTDETAIL,
           wa type Z6731_DEPTDETAIL.
    wa-DEPT_ID = 'z897hkjh'.
    wa-DESCRIPTION = 'computer'.
    append wa to itab.
    wa-DEPT_ID = 'z897hkjhd'.
    wa-DESCRIPTION = 'computer'.
    append wa to itab.
    loop at itab into wa.
    insert z6731_DEPTDETAIL from wa.
    endloop.
    rewards if helpful

  • Oracle 11g imp erroneously tries to recreate existing tables with CLOBs?

    I have a shell script for loading database dumps from both Datapump and the older exp/imp.
    Often when loading dumps, I need to rename the schema owner and tablespace names (which is handled by REMAP_SCHEMA and REMAP_TABLESPACE in Datapump).
    However I have a whole bunch of dumps created with exp at this point and not that many Datapump dumps yet. As such the old style dumps are handled by the shell script in this way:
    1) A first pass imp is run using INDEXFILE to generate a file with the SQL to create tables and indexes. Options also include FROMUSER and TOUSER.
    2) A series of sed command edit the SQL file to change the tablespace names (which are schema owner specific in our case).
    3) The editted SQL file is run with sqlplus to create the tables and indexes.
    4) A second pass imp is run to load the table rows as well as triggers, stored procedures, views, etc. Options include FROMUSER, TOUSER, COMMIT=Y, IGNORE=Y, BUFFER, STATISTICS=NONE, CONSTRAINTS=N
    This shell script has been working great for loading exp dump files into Oracle 9 and Oracle 10 databases, but now that I'm trying to load these dumps into Oracle 11, it fails.
    The problem is in step 4, the imp program is trying to create some of the tables that already were created with sqlplus in step 2. The problematic tables all seem to have CLOB columns in them. The table creation fails because it tries to use the tablespace names from the dump file, which do not exist in the destination database. And when the table creation fails, imp then decides not to load the rows for those table.
    This seems like a bug in the Oracle 11 imp program. I don't understand why it thinks it needs to recreate tables that already exist when those tables have CLOB columns. Is there something different about CLOB columns in Oracle 11 that I should know about that might be confusing imp into thinking that it needs to create tables when they already exist? Maybe I need to do something to those tables in SQL so that imp does not think it needs to recreate them?
    I know that the tables with the CLOBs were created correctly because I was trying to find some way to workaround this. For step 4, I tried using DATA_ONLY=Y, in which case imp does not try to create the tables and just loads the table rows. Of course using DATA_ONLY, I don't get a lot of other things like triggers, view and stored procedures. I started to try to get around that by doing 3 passes with imp, so that I could pick up the missing pieces by using an imp pass with ROWS=N, but strangely that has the same problem of trying to recreate the existing tables.

    The only solution I've found so far as a workaround is rather convoluted.
    1. I took an export using datapump's expdp of SCHEMA1 (in 10g it will skip the table with the xmltype).
    2. I imported the data to my empty schema (SCHEMA2) using impdp. To avoid the error that the type already exists with another OID, I used the TRANSFORM=oid:n parameter e.g.
    impdp user/pwd dumpfile=noxmltable.dmp logfile=importallbutxmltable.log remap_schema=SCHEMA1:SCHEMA2 TRANSFORM=oid:n directory=MYDUMPDIR
    3. I then manually created my xmltype table in the SCHEMA2 and did a select into to load it (make sure you have the select privileges to do so):
    INSERT INTO SCHEMA2.XMLTABLE2 SELECT * FROM SCHEMA1.XMLTABLE1;
    4. I am still taking an export with exp of the xmltable as well even though I'm not sure I can do anything with it.
    Thanks!
    Edited by: stacyz on Jul 28, 2009 9:49 AM

  • How to create a table with data in it?

    I need to have a temp table in a PL/SQL procedure for processing which can hold data values from two other tables and a sequence number.
    Ex:
    Existing tables:
    table1 (col1 varchar2(100), col2 date, col3 number20) - Has more 1Lakh rows
    table2 (col1 varchar2(100), col2 date) - Has more 900 rows
    New table
    temp_table (col1 PRY KEY(seq1.number), col2 varchar2(100), col3 date)
    Currently i have created the temp_table and inserting all the data from both table1 & table2 (which is poor). Please suggest me a way to have the temp_table created with data(atleast from table1 which has more than 1Lakh rows). Please see i need a sequence number as well.
    Thanks in advance.

    Vel wrote:
    I am creating XML file using DBMS_XMLGEN package. This XML file will contain data from two different database tables. So I am creating temporary table in the PL/SQL procedure to have the data from these different tables in a single temporary table.
    Please find the below Dynamic SQL statements that i'm using for create the temp table and inserting the data into it.
    Before insert the V_NAME filed, i will be appending a VARCHAR field to the original data.
    EXECUTE IMMEDIATE 'CREATE TABLE TEMP_TABLE (UNIQUE_KEY NUMBER , FILE_NAME VARCHAR2(1000), LAST_DATE DATE)';
    EXECUTE IMMEDIATE 'INSERT INTO TEMP_TABLE values (SEQUENCE.nextval,:1,:2)' USING V_NAME,vLastDate;What exactly i need is to eliminate the INSERT portion of it,Since i have to insert more 90,000 rows into it. Is there way to have the temp table created with data in it along with the sequence value as well.
    I'm using Oracle 10.2.0.4 version.
    Edited by: 903948 on Dec 22, 2011 10:58 PMWhat you need to do to eliminate the INSERT statement is to -- as already suggested by others - eliminate the temporary table. You don't need it. It is just necessary overhead. Please explain why you (apparently) believe that the suggestion of a view will not meet your requirements.

  • New DB from existing DB with data

    Hi All,
    How to create new DB from an existing DB with all the data? means what could be the sql for that. ?

    i mean to say when we want create a table in db from an existing db with data then we write like
    create table <table_name> as select * from <db_name>.<table_name>
    so is there any sql like this for creating db from an existing db with data?

  • Not able to rename the existing file

    Hi All,
    I have a java file Test.java in which i am doing the following stuffs.
    1) I am creating a new file
    2) Entering contents in the existing file
    3) Renaming the existing file--When i am doing this i am not getting any error but the existing file is not renamed
    The contents of the file Test.java*************************
    package com.fidelity.ereview.utils;
    import java.io.*;
    public class Testing {
         public static void main(String[] args) throws IOException {
              File f = new File("D:/TCS/myfile1.txt");
              f.createNewFile();
              System.out.println("new file " + f + " is created");
              FileOutputStream fileobj = new FileOutputStream(f);
              DataOutputStream writeInsideFileObj = new DataOutputStream(fileobj);
              writeInsideFileObj.writeBytes("sunita");
              writeInsideFileObj.writeBytes(",");
              writeInsideFileObj.writeBytes("choudhury");
              File f2 = new File("D:/TCS/myfile2.csv");
              f.renameTo(f2); **// renames the file HERE The file is not renamed**
    Kindly anybody help me....

    import java.io.*;
    public class Testing {
    public static void main(String[] args) throws IOException {
    //File f = new File("D:/TCS/myfile1.txt");
    File f = new File("D:/TCS/myfile2.csv");//above replaced by
    f.createNewFile();
    System.out.println("new file " + f + " is created");
    FileOutputStream fileobj = new FileOutputStream(f);
    DataOutputStream writeInsideFileObj = new DataOutputStream(fileobj);
    writeInsideFileObj.writeBytes("sunita");
    writeInsideFileObj.writeBytes(",");
    writeInsideFileObj.writeBytes("choudhury");
    writeInsideFileObj.close();//I added
    fileobj.close();//I added
    //File f2 = new File("D:/TCS/myfile2.csv");
    //f.renameTo(f2); **// renames the file HERE The file is not renamed**
    }Why create a file add data to the file and then rename to change the file type?
    You can add data to any file type with java.

  • Get "Creation Script" of the existing table ( in SQL database) using C# and without using SMO dlls

    Hi All,
    I need to get the "Creation Script" of the existing table using c# and without using SMO dlls (is it possible? I don't know).
    I.e. In SQL Management Studio -> right click on any table -> Script table as -> Create To  - > open in the new query editor window. This will give you the schema of the table with the constraints of the table.
    For E.g. In Northwind database, for the table "Categories", I would like to get it as show below
    USE [Northwind]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Categories](
        [CategoryID] [int] IDENTITY(1,1) NOT NULL,
        [CategoryName] [nvarchar](15) NOT NULL,
        [Description] [ntext] NULL,
        [Picture] [image] NULL,
     CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED
        [CategoryID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    I would like to get the same schema using c#. Please help.
    Thanks & Regards,
    Kalai.

    SMO is the easiest way to get this. This is what Management Studio uses. If you can't use SMO, get a Profiler trace of the queries that SMO executes when generating the script and execute the same using ADO.NET.
    Regards,
    Farooq Mahmud
    Support Escalation Engineer 
    •  Microsoft Health Solutions Group

  • Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the rows? Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    Hello Anybody, I have a question. Can any of you please suggest me how to make an xml file from the database table with all the records?
    Note:- I am having the XSD Schema file and the resulted XML file should be in that XSD format only.

    The Oracle documentation has a good overview of the options available
    Generating XML Data from the Database
    Without knowing your version, I just picked 11.2, so you made need to look for that chapter in the documentation for your version to find applicable information.
    You can also find some information in XML DB FAQ

Maybe you are looking for

  • Keynote- Can you add multiple sound tracks to one presentation

    Can multiple sound tracks be added to the same presentation? For instance, can I add one sound track to play for slides 1-20 and a second, different sound track to play starting at slide 23 thru 36?

  • Issue with At selection-screen output

    Hi,   I tried in SDn to find suitable thread atlast i am creating query here. My requirement is: i have two radiobuttons. when i click first radiobutton it hasto show one selection screen it contains pernr and bukrs when i click second radiobutton it

  • Solaris 10 x86 on IBM x346

    Hi All, I've currently got Solaris 10 x86 installed successfully on an IBM x346 which is a 1 proc 3.06GHz HT Xeon supporting EM64T and 1GB ram. Everything works, except the most important device, network. It's got two bge's onboard, I had to add the

  • Non of the chortcuts works in pages on my ipad with  apples keyboard

    As the headline says. I bought Pages and a seperate keybord to be able to use my iPad at school. I'm not able to use the chortcuts. For example cmd + B does not work. now i have to reach forvard and touch the screen every time i need someting... Does

  • BPC 7.5 NW - EVDRE builder blank

    Hello all. I have a problem with my BPC NW system. I have installed BPC 7.5 SP05 in my server, and the client I am using is at SP05 Patch 2 level. There are two Appsets: the ApShell (with Rate and Planning applications) and one more which I created.