How to: Count columns in a table?

Quite simple question actually. How do I count the number of columns in a table using SQL?

For AdventureWorks2012 tables & views:
SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COUNT(COLUMN_NAME ) ColCount
FROM INFORMATION_SCHEMA.COLUMNS
GROUP BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME
ORDER BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME;
TABLE_SCHEMA TABLE_NAME ColCount
dbo AWBuildVersion 4
dbo DatabaseLog 8
dbo ErrorLog 9
HumanResources Department 4
HumanResources Employee 16
HumanResources EmployeeDepartmentHistory 6
HumanResources EmployeePayHistory 5
HumanResources JobCandidate 4
HumanResources Shift 5
HumanResources vEmployee 18
HumanResources vEmployeeDepartment 10
HumanResources vEmployeeDepartmentHistory 11
HumanResources vJobCandidate 16
HumanResources vJobCandidateEducation 13
HumanResources vJobCandidateEmployment 11
Person Address 9
Person AddressType 4
Person BusinessEntity 3
Person BusinessEntityAddress 5
Person BusinessEntityContact 5
Person ContactType 3
Person CountryRegion 3
Person EmailAddress 5
Person Password 5
Person Person 13
Person PersonPhone 4
Person PhoneNumberType 3
Person StateProvince 8
Person vAdditionalContactInfo 17
Person vStateProvinceCountryRegion 7
Production BillOfMaterials 9
Production Culture 3
Production Document 14
Production Illustration 3
Production Location 5
Production Product 25
Production ProductCategory 4
Production ProductCostHistory 5
Production ProductDescription 4
Production ProductDocument 3
Production ProductInventory 7
Production ProductListPriceHistory 5
Production ProductModel 6
Production ProductModelIllustration 3
Production ProductModelProductDescriptionCulture 4
Production ProductPhoto 6
Production ProductProductPhoto 4
Production ProductReview 8
Production ProductSubcategory 5
Production ScrapReason 3
Production TransactionHistory 9
Production TransactionHistoryArchive 9
Production UnitMeasure 3
Production vProductAndDescription 5
Production vProductModelCatalogDescription 25
Production vProductModelInstructions 11
Production WorkOrder 10
Production WorkOrderRouting 12
Purchasing ProductVendor 11
Purchasing PurchaseOrderDetail 11
Purchasing PurchaseOrderHeader 13
Purchasing ShipMethod 6
Purchasing Vendor 8
Purchasing vVendorWithAddresses 9
Purchasing vVendorWithContacts 12
Sales CountryRegionCurrency 3
Sales CreditCard 6
Sales Currency 3
Sales CurrencyRate 7
Sales Customer 7
Sales PersonCreditCard 3
Sales SalesOrderDetail 11
Sales SalesOrderHeader 26
Sales SalesOrderHeaderSalesReason 3
Sales SalesPerson 9
Sales SalesPersonQuotaHistory 5
Sales SalesReason 4
Sales SalesTaxRate 7
Sales SalesTerritory 10
Sales SalesTerritoryHistory 6
Sales ShoppingCartItem 6
Sales SpecialOffer 11
Kalman Toth Database & OLAP Architect
sqlusa.com
Paperback / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012

Similar Messages

  • How to make column headers in table in PDF report appear bold while datas in table appear regular from c# windows forms with sql server2008 using iTextSharp

    Hi my name is vishal
    For past 10 days i have been breaking my head on how to make column headers in table appear bold while datas in table appear regular from c# windows forms with sql server2008 using iTextSharp.
    Given below is my code in c# on how i export datas from different tables in sql server to PDF report using iTextSharp:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using iTextSharp.text;
    using iTextSharp.text.pdf;
    using System.Diagnostics;
    using System.IO;
    namespace DRRS_CSharp
    public partial class frmPDF : Form
    public frmPDF()
    InitializeComponent();
    private void button1_Click(object sender, EventArgs e)
    Document doc = new Document(PageSize.A4.Rotate());
    var writer = PdfWriter.GetInstance(doc, new FileStream("AssignedDialyzer.pdf", FileMode.Create));
    doc.SetMargins(50, 50, 50, 50);
    doc.SetPageSize(new iTextSharp.text.Rectangle(iTextSharp.text.PageSize.LETTER.Width, iTextSharp.text.PageSize.LETTER.Height));
    doc.Open();
    PdfPTable table = new PdfPTable(6);
    table.TotalWidth =530f;
    table.LockedWidth = true;
    PdfPCell cell = new PdfPCell(new Phrase("Institute/Hospital:AIIMS,NEW DELHI", FontFactory.GetFont("Arial", 14, iTextSharp.text.Font.BOLD, BaseColor.BLACK)));
    cell.Colspan = 6;
    cell.HorizontalAlignment = 0;
    table.AddCell(cell);
    Paragraph para=new Paragraph("DCS Clinical Record-Assigned Dialyzer",FontFactory.GetFont("Arial",16,iTextSharp.text.Font.BOLD,BaseColor.BLACK));
    para.Alignment = Element.ALIGN_CENTER;
    iTextSharp.text.Image png = iTextSharp.text.Image.GetInstance("logo5.png");
    png.ScaleToFit(105f, 105f);
    png.Alignment = Element.ALIGN_RIGHT;
    SqlConnection conn = new SqlConnection("Data Source=NPD-4\\SQLEXPRESS;Initial Catalog=DRRS;Integrated Security=true");
    SqlCommand cmd = new SqlCommand("Select d.dialyserID,r.errorCode,r.dialysis_date,pn.patient_first_name,pn.patient_last_name,d.manufacturer,d.dialyzer_size,r.start_date,r.end_date,d.packed_volume,r.bundle_vol,r.disinfectant,t.Technician_first_name,t.Technician_last_name from dialyser d,patient_name pn,reprocessor r,Techniciandetail t where pn.patient_id=d.patient_id and r.dialyzer_id=d.dialyserID and t.technician_id=r.technician_id and d.deleted_status=0 and d.closed_status=0 and pn.status=1 and r.errorCode<106 and r.reprocessor_id in (Select max(reprocessor_id) from reprocessor where dialyzer_id=d.dialyserID) order by pn.patient_first_name,pn.patient_last_name", conn);
    conn.Open();
    SqlDataReader dr;
    dr = cmd.ExecuteReader();
    table.AddCell("Reprocessing Date");
    table.AddCell("Patient Name");
    table.AddCell("Dialyzer(Manufacturer,Size)");
    table.AddCell("No.of Reuse");
    table.AddCell("Verification");
    table.AddCell("DialyzerID");
    while (dr.Read())
    table.AddCell(dr[2].ToString());
    table.AddCell(dr[3].ToString() +"_"+ dr[4].ToString());
    table.AddCell(dr[5].ToString() + "-" + dr[6].ToString());
    table.AddCell("@count".ToString());
    table.AddCell(dr[12].ToString() + "-" + dr[13].ToString());
    table.AddCell(dr[0].ToString());
    dr.Close();
    table.SpacingBefore = 15f;
    doc.Add(para);
    doc.Add(png);
    doc.Add(table);
    doc.Close();
    System.Diagnostics.Process.Start("AssignedDialyzer.pdf");
    if (MessageBox.Show("Do you want to save changes to AssignedDialyzer.pdf before closing?", "DRRS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.Yes)
    var writer2 = PdfWriter.GetInstance(doc, new FileStream("AssignedDialyzer.pdf", FileMode.Create));
    else if (MessageBox.Show("Do you want to save changes to AssignedDialyzer.pdf before closing?", "DRRS", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.No)
    this.Close();
    The above code executes well with no problem at all!
    As you can see the file to which i create and save and open my pdf report is
    AssignedDialyzer.pdf.
    The column headers of table in pdf report from c# windows forms using iTextSharp are
    "Reprocessing Date","Patient Name","Dialyzer(Manufacturer,Size)","No.of Reuse","Verification" and
    "DialyzerID".
    However the problem i am facing is after execution and opening of document is my
    column headers in table in pdf report from
    c# and datas in it all appear in bold.
    I have browsed through net regarding to solve this problem but with no success.
    What i want is my pdf report from c# should be similar to following format which i was able to accomplish in vb6,adodb with MS access using iTextSharp.:
    Given below is report which i have achieved from vb6,adodb with MS access using iTextSharp
    I know that there has to be another way to solve my problem.I have browsed many articles in net regarding exporting sql datas to above format but with no success!
    Is there is any another way to solve to my problem on exporting sql datas from c# windows forms using iTextSharp to above format given in the picture/image above?!
    If so Then Can anyone tell me what modifications must i do in my c# code given above so that my pdf report from c# windows forms using iTextSharp will look similar to image/picture(pdf report) which i was able to accomplish from
    vb6,adodb with ms access using iTextSharp?
    I have approached Sound Forge.Net for help but with no success.
    I hope anyone/someone truly understands what i am trying to ask!
    I know i have to do lot of modifications in my c# code to achieve this level of perfection but i dont know how to do it.
    Can anyone help me please! Any help/guidance in solving this problem would be greatly appreciated.
    I hope i get a reply in terms of solving this problem.
    vishal

    Hi,
    About iTextSharp component issue , I think this case is off-topic in here.
    I suggest you consulting to compenent provider.
    http://sourceforge.net/projects/itextsharp/
    Regards,
    Marvin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to encrypt column of some table with the single method  on oracle7/814?

    How to encrypt column of some table with the single method on oracle7/814?

    How to encrypt column of some table with the single method on oracle7/814?

  • How to encrypt column of some table with the single method ?

    How to encrypt column of some table with the single method ?

    How to encrypt column of some table with the single
    method ?How to encrypt column of some table with the single
    method ?
    using dbms_crypto package
    Assumption: TE is a user in oracle 10g
    we have a table need encrypt a column, this column SYSDBA can not look at, it's credit card number.
    tha table is
    SQL> desc TE.temp_sales
    Name Null? Type
    CUST_CREDIT_ID NOT NULL NUMBER
    CARD_TYPE VARCHAR2(10)
    CARD_NUMBER NUMBER
    EXPIRY_DATE DATE
    CUST_ID NUMBER
    1. grant execute on dbms_crypto to te;
    2. Create a table with a encrypted columns
    SQL> CREATE TABLE te.customer_credit_info(
    2 cust_credit_id number
    3      CONSTRAINT pk_te_cust_cred PRIMARY KEY
    4      USING INDEX TABLESPACE indx
    5      enable validate,
    6 card_type varchar2(10)
    7      constraint te_cust_cred_type_chk check ( upper(card_type) in ('DINERS','AMEX','VISA','MC') ),
    8 card_number blob,
    9 expiry_date date,
    10 cust_id number
    11      constraint fk_te_cust_credit_to_cust references te.customer(cust_id) deferrable
    12 )
    13 storage (initial 50k next 50k pctincrease 0 minextents 1 maxextents 50)
    14 tablespace userdata_Lm;
    Table created.
    SQL> CREATE SEQUENCE te.customers_cred_info_id
    2 START WITH 1
    3 INCREMENT BY 1
    4 NOCACHE
    5 NOCYCLE;
    Sequence created.
    Note: Credit card number is blob data type. It will be encrypted.
    3. Loading data encrypt the credit card number
    truncate table TE.customer_credit_info;
    DECLARE
    input_string VARCHAR2(16) := '';
    raw_input RAW(128) := UTL_RAW.CAST_TO_RAW(CONVERT(input_string,'AL32UTF8','US7ASCII'));
    key_string VARCHAR2(8) := 'AsDf!2#4';
    raw_key RAW(128) := UTL_RAW.CAST_TO_RAW(CONVERT(key_string,'AL32UTF8','US7ASCII'));
    encrypted_raw RAW(2048);
    encrypted_string VARCHAR2(2048);
    BEGIN
    for cred_record in (select upper(CREDIT_CARD) as CREDIT_CARD,
    CREDIT_CARD_EXP_DATE,
    to_char(CREDIT_CARD_NUMBER) as CREDIT_CARD_NUMBER,
    CUST_ID
    from TE.temp_sales) loop
    dbms_output.put_line('type:' || cred_record.credit_card || 'exp_date:' || cred_record.CREDIT_CARD_EXP_DATE);
    dbms_output.put_line('number:' || cred_record.CREDIT_CARD_NUMBER);
    input_string := cred_record.CREDIT_CARD_NUMBER;
    raw_input := UTL_RAW.CAST_TO_RAW(CONVERT(input_string,'AL32UTF8','US7ASCII'));
    dbms_output.put_line('> Input String: ' || CONVERT(UTL_RAW.CAST_TO_VARCHAR2(raw_input),'US7ASCII','AL32UTF8'));
    encrypted_raw := dbms_crypto.Encrypt(
    src => raw_input,
    typ => DBMS_CRYPTO.DES_CBC_PKCS5,
    key => raw_key);
    encrypted_string := rawtohex(UTL_RAW.CAST_TO_RAW(encrypted_raw)) ;
    dbms_output.put_line('> Encrypted hex value : ' || encrypted_string );
    insert into TE.customer_credit_info values
    (TE.customers_cred_info_id.nextval,
    cred_record.credit_card,
    encrypted_raw,
    cred_record.CREDIT_CARD_EXP_DATE,
    cred_record.CUST_ID);
    end loop;
    commit;
    end;
    4. Check credit card number script
    DECLARE
    input_string VARCHAR2(16) := '';
    raw_input RAW(128) := UTL_RAW.CAST_TO_RAW(CONVERT(input_string,'AL32UTF8','US7ASCII'));
    key_string VARCHAR2(8) := 'AsDf!2#4';
    raw_key RAW(128) := UTL_RAW.CAST_TO_RAW(CONVERT(key_string,'AL32UTF8','US7ASCII'));
    encrypted_raw RAW(2048);
    encrypted_string VARCHAR2(2048);
    decrypted_raw RAW(2048);
    decrypted_string VARCHAR2(2048);
    cursor cursor_cust_cred is select CUST_CREDIT_ID, CARD_TYPE, CARD_NUMBER, EXPIRY_DATE, CUST_ID
    from TE.customer_credit_info order by CUST_CREDIT_ID;
    v_id customer_credit_info.CUST_CREDIT_ID%type;
    v_type customer_credit_info.CARD_TYPE%type;
    v_EXPIRY_DATE customer_credit_info.EXPIRY_DATE%type;
    v_CUST_ID customer_credit_info.CUST_ID%type;
    BEGIN
    dbms_output.put_line('ID Type Number Expiry_date cust_id');
    dbms_output.put_line('-----------------------------------------------------');
    open cursor_cust_cred;
    loop
         fetch cursor_cust_cred into v_id, v_type, encrypted_raw, v_expiry_date, v_cust_id;
    exit when cursor_cust_cred%notfound;
    decrypted_raw := dbms_crypto.Decrypt(
    src => encrypted_raw,
    typ => DBMS_CRYPTO.DES_CBC_PKCS5,
    key => raw_key);
    decrypted_string := CONVERT(UTL_RAW.CAST_TO_VARCHAR2(decrypted_raw),'US7ASCII','AL32UTF8');
    dbms_output.put_line(V_ID ||' ' ||
    V_TYPE ||' ' ||
    decrypted_string || ' ' ||
    v_EXPIRY_DATE || ' ' ||
    v_CUST_ID);
    end loop;
    close cursor_cust_cred;
    commit;
    end;
    /

  • How to rename column name of table?

    Hello...
    How to rename column name of table?
    The column have data.
    Thanks.
    Martonio.

    The following should work in 9i release 2 and above.
    SQL> create table mytable(col1 varchar2(2),
      2  col2 date);
    Table created.
    SQL> insert into mytable values('t1',sysdate);
    1 row created.
    SQL> select * from mytable;
    CO COL2
    t1 30-NOV-04
    1 row selected.
    SQL> desc mytable
    Name                                      Null?    Type
    COL1                                               VARCHAR2(2)
    COL2                                               DATE
    SQL> alter table mytable rename column col2 to mydate;
    Table altered.
    SQL> desc mytable
    Name                                      Null?    Type
    COL1                                               VARCHAR2(2)
    MYDATE                                             DATE
    SQL> select * from mytable;
    CO MYDATE
    t1 30-NOV-04
    1 row selected.
    SQL> disconnect
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.3.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.3.0 - Productionhttp://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/wnsql.htm#972698

  • How to encrypt column of some tables on oracle734/oracle817 ?

    How to encrypt column of some tables on oracle734/oracle817 ?

    Unless you are very good writing C ... upgrade to a version of the product supported during the current millennium.

  • How to select columns in a table by their column id and not the column name

    Hello,
    How do you select columns from a table based on their column_id.
    I have create a view
    but other than Select * , i cant now select one just one column from it
    the view as follow:
    create view count_student as
    select a.acode "acode",aname "Activity Name",count(ae.acode) "Number of student joined"
    from aenrol ae, activity a
    where a.acode= ae.acode
    group by a.acode,aname;

    The issue is that you have decided to use quoted column names. A pretty horrible idea (mostly for the reasons that you are now finding).
    Re-create the view and get rid of the silly double quotes.

  • How to count records from 2 tables and show in RDLC Report

    hi all,
    its being a one day searching for the solution but No Luck.
     I have two SQL tables tblstudetail and tblfeereceiptdetail.
    i just want to count records from both tables and show in RDLC report.
    I tried SQl Query Like This:
    select a.session, a.course,
    Count(CASE a.ADstatus WHEN 'OK' THEN 1 ELSE 0 END ) AS Admission,
    Count(CASE s .I_receiptstatus WHEN 'OK' THEN 1 ELSE 0 END) AS Feeprint
    from
    tblstudetail a
    FULL join
    tblfeereceiptdetail s on s.studentID = a.studentID
    where a.session = '2015' AND s.Fsession = '2015' AND a.adcat = 'Regular'
    GROUP BY a.session,a.course
    ORDER by a.course
    The result Show the Same Value in Both columns
    Session    Course      Admission       FeeDetail
    2015          B.A. I               275              275
    2015          B.A. II              307             307
    2015         B.A. III             255            255
    2015          B.Sc. I             110             110
    2015           B.Sc. II           105            105
    2015          B.Sc. III            64               64
    Actully I want to Count How many ADMISSION have been Taken(FROM tblstudetail) and How many FEE RECEIPT have been Print (From tblfeereceiptdetail).
    please guide me for this as soon as possible.
    thanks in advance...

    I am counting 'OK' in both the table columns I.e 'ADstatus' in tblstudetail and 'feereceiptstatus' in tblfeereceiptdetail
    please suggest me

  • How i add Columns to my table ?

    Guys, im not being able to add my columns to the table, can anyone help me ?
    Thanks!
    TableView<String> tv = new TableView<>();
      tv.setVisible(true);
           TableColumn firstNameCol = new TableColumn();
           TableColumn lastNameCol = new TableColumn();
           TableColumn emailCol = new TableColumn();
           tv.getColumns().add(0,firstNameCol);

    Woah! Thanks man! it works greatly but.... Theres just 1 more issue!! i read all the javaDoc and asked help to a friend but we were unable to find a solution, also, im using the "Introduction to javaFX 2 book".
    Im sorry to keep troubling you guys, but it seems javaFX isnt taking off here, and i sometimes think im one of the first in Brasil to starting learning it.
    They teach java in my College, but i think javaFX is a way better "swing/interface" than the one in java. Anyway , the problem im having is : I need get the data from a db , no problem with that, but how can i insert that data? I tried several solutions but none worked.
    Can you help me one more time :D ? Please!!
    thanks a lot guys
    Anyway, heres what the classes are :
    Main Class :
    package voosparaweb;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    * @author André Vinícius Lopes
    public class Voos {
        public static void main(String args[])
         VoosParaWeb v1 = new VoosParaWeb();
         v1.main(args);
         //The Code Below doesnt  work
         v1.testingDataSetTable("1","13:00","Roma");
    }voosParaWeb Class
    package voosparaweb;
    import javafx.application.Application;
    import javafx.collections.ObservableList;
    import javafx.scene.Group;
    import javafx.scene.Scene;
    import javafx.scene.control.TableColumn;
    import javafx.scene.control.TableView;
    import javafx.scene.control.cell.PropertyValueFactory;
    import javafx.scene.layout.GridPane;
    import javafx.stage.Stage;
    * @author André
    public class VoosParaWeb extends Application {
      public TableView<Data> t1 = new TableView<Data>();
      public static void main(String[] args) {
        launch(args);
      @Override
      public void start(Stage primaryStage) {
        Group root = new Group();
        GridPane gp = new GridPane();
        root.getChildren().add(gp);
        Scene scene = new Scene(root, 640, 480);
        t1 = tvset();
        setDataTable();
        t1.setVisible(true);
        gp.add(t1, 1, 1);
         //The Code Below work
        // v1.testingDataSetTable("1","13:00","Roma");
        primaryStage.setTitle("Terminals Panel");
        primaryStage.setScene(scene);
        primaryStage.show();
      public TableView<Data> tvset()
        String Person;
        ObservableList<VoosParaWeb> data;
        TableView<Data> tv = new TableView<Data>();
        tv.setVisible(true);
        TableColumn<Data, String> idTc = new TableColumn<Data, String>("ID#");
        idTc.setCellValueFactory(new PropertyValueFactory("id"));
        TableColumn<Data, String> timeTc = new TableColumn<Data, String>("Time");
        timeTc.setCellValueFactory(new PropertyValueFactory("time"));
        TableColumn<Data, String> destinyTc = new TableColumn<Data, String>("Destiny");
        destinyTc.setCellValueFactory(new PropertyValueFactory("destiny"));
        TableColumn flightTc = new TableColumn("Flight");
        TableColumn counterTc = new TableColumn("Counter");
        TableColumn boardingTc = new TableColumn("Boarding");
        TableColumn gateTc = new TableColumn("Gate");
        TableColumn statusTc = new TableColumn("Status");
        tv.getColumns().add(idTc);
        tv.getColumns().add(timeTc);
        tv.getColumns().add(destinyTc);
        tv.getColumns().add(flightTc);
        tv.getColumns().add(counterTc);
        tv.getColumns().add(boardingTc);
        tv.getColumns().add(gateTc);
        tv.getColumns().add(statusTc);
        return tv;
      public void setDataTable()
        t1.getItems().add(new Data("1", "1:15", "Amsterdam"));
      public void testingDataSetTable(String i,String time,String dest)
        t1.getItems().add(new Data(i,time,dest));
        t1.setVisible(true);
      public static class Data {
        private String id;
        private String time;
        private String destiny;
        public Data()
        public Data(String id, String time, String destiny) {
          this.id = id;
          this.time = time;
          this.destiny = destiny;
        public String getId() {
          return id;
        public String getTime() {
          return time;
        public String getDestiny() {
          return destiny;
    }

  • How to make columns in a table dynamic

    Hi,
    I want to make the columns of a table dynamic.
    At design time I dont know how many columns will be required.
    Rows are made dynamic by using the bean concept.
    Please help me in this reference(columns).
    Thanks
    Pooja

    Hi, i don't know how you create the rows dynamically but
    have you tried to use a forEach?
    <af:table ...>
    <af:forEach items="..." var="...">
    <af:column headerText="...">
    <af:outputText value="..."/>
    </af:column>
    </af:forEach>
    </af:table>
    here there is an example of a dynamic panelList:
    <af:panelList rows="3" maxColumns="6">
    <af:forEach items="#{bindings.ContratosView1.rangeSet}" var="li">
    <af:commandLink text="#{li.Codigo}" action="Edit"/>
    </af:forEach>
    </af:panelList>

  • How to find columns in a table ?

    Hi
    I want a sql query to find a columns in specfic table
    all i hav in hand is the name of the table and a value which i know is in the columns but dont know which column
    for example i know there is table named student with 15 columns and a value of a column is 'ABC' but i dont have the name of the column
    how to find the table using SQL query
    Thanks in Advance
    Bala

    SELECT column_name,
      table_name
       FROM user_tab_cols
      WHERE table_name IN ('<yourtablenamehere>')
    AND extractvalue(dbms_xmlgen.getxmltype('select ''Found'' col from '|| table_name ||' where rownum=1 and ' || CASE WHEN data_type IN
          ( SELECT DISTINCT data_type FROM user_tab_cols WHERE data_type NOT LIKE 'TIME%' AND data_type != 'DATE' )
        THEN column_name ELSE 'to_char('||column_name||',''DD-MM-YYYY HH24:MI:ss'')'  END
      ||' = ''<yourcolumnvaluetobefound>'' '),'//COL')='Found';Fill <yourtablenamehere> and <yourcolumnvaluetobefound> in the above query and get the result.
    Ravi Kumar

  • How to get column names in table maintenance dialog?

    I created a new Z table and created a maintanance dialog so that I can maintain the table through sm30. i don't see columns names on maintenance screen, just a "+" sign for each column! Could someone please tell me how to display column name?
    Thanks.
    Mithun

    Hello Mithun
    The column texts are taken from the field descriptions of the data elements used in your z-table. A "+" sign usually indicates that none of the field descriptions of the data element has been maintained.
    Regards
      Uwe

  • How to add column to compressed table

    Hi gurus,
    Can any one help me how to add a column to compressed tables
    Thanks in advance

    The only difference is if added column has default value. In that case:
    SQL> create table tbl(id number,val varchar2(10))
      2  /
    Table created.
    SQL> insert into tbl
      2  select level,lpad('X',10,'X')
      3  from dual
      4  connect by level <= 100000
      5  /
    100000 rows created.
    SQL> select bytes
      2  from user_segments
      3  where segment_name = 'TBL'
      4  /
         BYTES
       3145728
    SQL> alter table tbl move compress
      2  /
    Table altered.
    SQL> select bytes
      2  from user_segments
      3  where segment_name = 'TBL'
      4  /
         BYTES
       2097152
    SQL> alter table tbl add name varchar2(5) default 'NONE'
      2  /
    alter table tbl add name varchar2(5) default 'NONE'
    ERROR at line 1:
    ORA-39726: unsupported add/drop column operation on compressed tables
    SQL> alter table tbl add name varchar2(5)
      2  /
    Table altered.
    SQL> update tbl set name = 'NONE'
      2  /
    100000 rows updated.
    SQL> commit
      2  /
    Commit complete.
    SQL> select bytes
      2  from user_segments
      3  where segment_name = 'TBL'
      4  /
         BYTES
       7340032
    SQL> select compression from user_tables where table_name = 'TBL'
      2  /
    COMPRESS
    ENABLED
    SQL> alter table tbl move compress
      2  /
    Table altered.
    SQL> select bytes
      2  from user_segments
      3  where segment_name = 'TBL'
      4  /
         BYTES
       2097152
    SQL> SY.

  • How to count total no. of tables existed?

    Dear Friends,
    I am new to SQL.
    While doing practise, I've created a number of tables at the SQL prompt. And now I don't remember the name of all the tables.
    So, please suggest an sql statement like how to count the total number of tables existing there.
    Your feedback is appreciated.
    Kindest regards,
    Lalit Sharma

    But could you pls be so kind and let me know how to
    do this as I mentioned above that I'm new to SQL.Hi,
    You would query USER_TABLES in the same way as you would query any of the tables that you have created. :
    SELECT column_list
    FROM table_name
    ...

  • How to count intials in a table

    I have a table (4 columns) used as a roster for fundraising. The table rows (1st Col) are dates eg; 4-Mar, 11-Mar etc. Columns 2-4 contain a members initials that are rostered for that date. (See below)
    What i would like is to be able to have a separate table (pivot table) that will count & give the number of total occurrences, ie; how many times a member is rostered in a particular period (month/year) Ideally this would update as filling out the roster
    so as to keep the roster spread across members
    MEMBERS
    Date
    M1
    M2
    M3
    4-Mar
    LR
    TM
    BN
    11-Mar
    GM
    AM
    PS
    18-Mar
    AM
    AH
    CA
    25-Mar
    LR
    KK
    AH
    1-Apr
    GM
    CR
    RB
    8-Apr
    TM
    GS
    AM
    15-Apr
    AM
    DA
    AC
    22-Apr
    LR
    CA
    KK
    Thanks in advance for any help

    Hi George
    Thanks for reply. Whilst the end result is what i'm after i'm trying to keep a single row for each date. The reasons are 
    1. As a table i can just tab across to enter member initials. (I may even have the initials as a list in data validation)
    2. Each member (M1, M2, M3) has a specific role to play when rostered on. So they need to know "their number"
    3. The roster will be printed (A4)up for distribution so the more compact the better
    I did think of having members listed in rows with the dates across in columns, but i couldnt get it to work how i wanted & it was also difficult to print on single page (the roster is done 6mth schedules).
    I'm starting to wonder whether i should perhap be looking to MS Access as i could link other data as well (not critical, but then again neither is this, it would just make it easier for me & any subsequent secretary/treasurer)
    I will keep play with options & would welcome any suggestions.
    Cheers

Maybe you are looking for