How to get the length one column in all tables in one database?List all SQL columns with max length AND greatest lengthHow does database indexing work?How to list the tables in a SQLite database file that was opened with ATTACH?Add a column with a default value to an existing table in SQL ServerHow to check if a column exists in a SQL Server table?How do I get list of all tables in a database using TSQL?Get list of all tables in Oracle?SQL select join: is it possible to prefix all columns as 'prefix.*'?What are the options for storing hierarchical data in a relational database?Find all tables containing column with specified name - MS SQL ServerGet size of all tables in database

What are the pros and cons for the two possible "gear directions" when parking the car on a hill?

Is "Busen" just the area between the breasts?

Why tighten down in a criss-cross pattern?

What are Elsa's reasons for selecting the Holy Grail on behalf of Donovan?

Why is oilcloth made with linseed oil?

Are all Ringwraiths called Nazgûl in LotR?

How to execute a command when ALL of the players are close enough

Is there a term for the belief that "if it's legal, it's moral"?

What's currently blocking the construction of the wall between Mexico and the US?

Why does using different ArrayList constructors cause a different growth rate of the internal array?

Can the pre-order traversal of two different trees be the same even though they are different?

What happened to Steve's Shield in Iron Man 2?

How to make clear to people I don't want to answer their "Where are you from?" question?

Is there a difference between an NFC and RFID chip?

Why do all the teams that I have worked with always finish a sprint without completion of all the stories?

Loss of power when I remove item from the outlet

Should I include an appendix for inessential, yet related worldbuilding to my story?

career in signal processing

Do I need a shock-proof watch for cycling?

Did the CIA blow up a Siberian pipeline in 1982?

Does a proton have a binding energy?

Story about a space war, and a human prisoner of war captured by alien enemy

How to parse 「場合でも」

Hit the Bulls Eye with T in the Center



How to get the length one column in all tables in one database?


List all SQL columns with max length AND greatest lengthHow does database indexing work?How to list the tables in a SQLite database file that was opened with ATTACH?Add a column with a default value to an existing table in SQL ServerHow to check if a column exists in a SQL Server table?How do I get list of all tables in a database using TSQL?Get list of all tables in Oracle?SQL select join: is it possible to prefix all columns as 'prefix.*'?What are the options for storing hierarchical data in a relational database?Find all tables containing column with specified name - MS SQL ServerGet size of all tables in database






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am having trouble to get the max length of records in one column in all tables.



I would only like to display the max length for each table for the specific column.



Below is what I have tried, I already found the way to return the column I need, but now, i need to get the max len. I know this is not the right way.



select max(len(site)) as site from 
(
SELECT t.name AS TableName
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE 'site%')A


The expected result will display the column name, the table name and also the max length of the records for that column.



Thanks in advance










share|improve this question

















  • 1





    Are you talking about column names, or table contents?

    – jarlh
    Mar 25 at 7:39











  • column name and table contents(data) sir. thanks

    – MichaelJ
    Mar 25 at 7:40











  • did you have a look here? stackoverflow.com/questions/14482897/…

    – Esteban P.
    Mar 25 at 7:42











  • I did, but it seems like i need to hard code my table name, i have more than 50 tables to check, so i tried using this way. will it be possible?

    – MichaelJ
    Mar 25 at 7:45











  • sys.columns and sys.tables can give you the longest column names. To find the longest table contents, you'll have to search each table. This seems to be a problem caused by a poor design. Start over from the beginning.

    – jarlh
    Mar 25 at 7:51

















1















I am having trouble to get the max length of records in one column in all tables.



I would only like to display the max length for each table for the specific column.



Below is what I have tried, I already found the way to return the column I need, but now, i need to get the max len. I know this is not the right way.



select max(len(site)) as site from 
(
SELECT t.name AS TableName
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE 'site%')A


The expected result will display the column name, the table name and also the max length of the records for that column.



Thanks in advance










share|improve this question

















  • 1





    Are you talking about column names, or table contents?

    – jarlh
    Mar 25 at 7:39











  • column name and table contents(data) sir. thanks

    – MichaelJ
    Mar 25 at 7:40











  • did you have a look here? stackoverflow.com/questions/14482897/…

    – Esteban P.
    Mar 25 at 7:42











  • I did, but it seems like i need to hard code my table name, i have more than 50 tables to check, so i tried using this way. will it be possible?

    – MichaelJ
    Mar 25 at 7:45











  • sys.columns and sys.tables can give you the longest column names. To find the longest table contents, you'll have to search each table. This seems to be a problem caused by a poor design. Start over from the beginning.

    – jarlh
    Mar 25 at 7:51













1












1








1








I am having trouble to get the max length of records in one column in all tables.



I would only like to display the max length for each table for the specific column.



Below is what I have tried, I already found the way to return the column I need, but now, i need to get the max len. I know this is not the right way.



select max(len(site)) as site from 
(
SELECT t.name AS TableName
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE 'site%')A


The expected result will display the column name, the table name and also the max length of the records for that column.



Thanks in advance










share|improve this question














I am having trouble to get the max length of records in one column in all tables.



I would only like to display the max length for each table for the specific column.



Below is what I have tried, I already found the way to return the column I need, but now, i need to get the max len. I know this is not the right way.



select max(len(site)) as site from 
(
SELECT t.name AS TableName
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE 'site%')A


The expected result will display the column name, the table name and also the max length of the records for that column.



Thanks in advance







sql sql-server






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 7:38









MichaelJMichaelJ

298




298







  • 1





    Are you talking about column names, or table contents?

    – jarlh
    Mar 25 at 7:39











  • column name and table contents(data) sir. thanks

    – MichaelJ
    Mar 25 at 7:40











  • did you have a look here? stackoverflow.com/questions/14482897/…

    – Esteban P.
    Mar 25 at 7:42











  • I did, but it seems like i need to hard code my table name, i have more than 50 tables to check, so i tried using this way. will it be possible?

    – MichaelJ
    Mar 25 at 7:45











  • sys.columns and sys.tables can give you the longest column names. To find the longest table contents, you'll have to search each table. This seems to be a problem caused by a poor design. Start over from the beginning.

    – jarlh
    Mar 25 at 7:51












  • 1





    Are you talking about column names, or table contents?

    – jarlh
    Mar 25 at 7:39











  • column name and table contents(data) sir. thanks

    – MichaelJ
    Mar 25 at 7:40











  • did you have a look here? stackoverflow.com/questions/14482897/…

    – Esteban P.
    Mar 25 at 7:42











  • I did, but it seems like i need to hard code my table name, i have more than 50 tables to check, so i tried using this way. will it be possible?

    – MichaelJ
    Mar 25 at 7:45











  • sys.columns and sys.tables can give you the longest column names. To find the longest table contents, you'll have to search each table. This seems to be a problem caused by a poor design. Start over from the beginning.

    – jarlh
    Mar 25 at 7:51







1




1





Are you talking about column names, or table contents?

– jarlh
Mar 25 at 7:39





Are you talking about column names, or table contents?

– jarlh
Mar 25 at 7:39













column name and table contents(data) sir. thanks

– MichaelJ
Mar 25 at 7:40





column name and table contents(data) sir. thanks

– MichaelJ
Mar 25 at 7:40













did you have a look here? stackoverflow.com/questions/14482897/…

– Esteban P.
Mar 25 at 7:42





did you have a look here? stackoverflow.com/questions/14482897/…

– Esteban P.
Mar 25 at 7:42













I did, but it seems like i need to hard code my table name, i have more than 50 tables to check, so i tried using this way. will it be possible?

– MichaelJ
Mar 25 at 7:45





I did, but it seems like i need to hard code my table name, i have more than 50 tables to check, so i tried using this way. will it be possible?

– MichaelJ
Mar 25 at 7:45













sys.columns and sys.tables can give you the longest column names. To find the longest table contents, you'll have to search each table. This seems to be a problem caused by a poor design. Start over from the beginning.

– jarlh
Mar 25 at 7:51





sys.columns and sys.tables can give you the longest column names. To find the longest table contents, you'll have to search each table. This seems to be a problem caused by a poor design. Start over from the beginning.

– jarlh
Mar 25 at 7:51












3 Answers
3






active

oldest

votes


















3














I don't understand what are you really trying to do, but I think you want something like



CREATE TABLE T1(
Site1 VARCHAR(45)
);
CREATE TABLE T2(
Site2 VARCHAR(45)
);

INSERT INTO T1 VALUES ('A'), ('AA');
INSERT INTO T2 VALUES ('BBB'), ('BBBBB');

DECLARE @SQL NVARCHAR(MAX) = 'SELECT ';

SELECT @SQL = @SQL +
N'(SELECT MAX(LEN(' + --You can also add ISNULL([Col],0) to get 0
QUOTENAME(c.name) + ')) FROM '+
QUOTENAME(t.name) + ') AS ' +
QUOTENAME(t.name + '.'+c.name) + ', '
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name LIKE 'site%';

SET @SQL = LEFT(@SQL, LEN(@SQL)-1);

EXEC sp_executesql @SQL;


Which will returns:



+----------+----------+
| T1.Site1 | T2.Site2 |
+----------+----------+
| 2 | 5 |
+----------+----------+


Live Demo






share|improve this answer
































    0














    Try this:You will get individual Scripts to execute.



    select 'select Max(len('+COLUMN_NAME+')),'''+COLUMN_NAME+ ''' as ColumnName ,'''+TABLE_NAME+''' as TableName from ' +table_name 
    from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME = 'YourColumnName'





    share|improve this answer























    • sorry i dont really get you

      – MichaelJ
      Mar 25 at 7:52











    • @MichaelJ The above code will get you the scripts which u have to execute in a loop to get the details of the Length of Column , Column Name and Table Name. Replace 'YourColumnName' with what ever column you are looking for.

      – Srikar mogaliraju
      Mar 25 at 9:22


















    0














    If I understand your question, you may try to generate a dynamic SQL statement and execute this statement:



    -- Declarations
    DECLARE @stm nvarchar(max)
    SET @stm = N''

    -- Dynamic SQL
    SELECT @stm = (
    SELECT CONCAT(
    N'UNION ALL ',
    N'SELECT ''',
    t.name,
    N''' AS TableName, ''',
    c.name,
    N''' AS ColumnName, ',
    N'ValueLength = (SELECT MAX(LEN(',
    QUOTENAME(c.name),
    ')) FROM ',
    QUOTENAME(t.name),
    N')'
    )
    FROM sys.columns c
    JOIN sys.tables t ON c.object_id = t.object_id
    WHERE c.name LIKE 'site%'
    ORDER BY t.name, c.name
    FOR XML PATH('')
    )
    SET @stm = STUFF(@stm, 1, 10, N'')

    -- Execution
    PRINT @stm
    EXEC sp_executesql @stm





    share|improve this answer























    • You are right sir, that is why i am looking for.

      – MichaelJ
      Mar 25 at 8:29











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333130%2fhow-to-get-the-length-one-column-in-all-tables-in-one-database%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    I don't understand what are you really trying to do, but I think you want something like



    CREATE TABLE T1(
    Site1 VARCHAR(45)
    );
    CREATE TABLE T2(
    Site2 VARCHAR(45)
    );

    INSERT INTO T1 VALUES ('A'), ('AA');
    INSERT INTO T2 VALUES ('BBB'), ('BBBBB');

    DECLARE @SQL NVARCHAR(MAX) = 'SELECT ';

    SELECT @SQL = @SQL +
    N'(SELECT MAX(LEN(' + --You can also add ISNULL([Col],0) to get 0
    QUOTENAME(c.name) + ')) FROM '+
    QUOTENAME(t.name) + ') AS ' +
    QUOTENAME(t.name + '.'+c.name) + ', '
    FROM sys.columns c
    JOIN sys.tables t ON c.object_id = t.object_id
    WHERE c.name LIKE 'site%';

    SET @SQL = LEFT(@SQL, LEN(@SQL)-1);

    EXEC sp_executesql @SQL;


    Which will returns:



    +----------+----------+
    | T1.Site1 | T2.Site2 |
    +----------+----------+
    | 2 | 5 |
    +----------+----------+


    Live Demo






    share|improve this answer





























      3














      I don't understand what are you really trying to do, but I think you want something like



      CREATE TABLE T1(
      Site1 VARCHAR(45)
      );
      CREATE TABLE T2(
      Site2 VARCHAR(45)
      );

      INSERT INTO T1 VALUES ('A'), ('AA');
      INSERT INTO T2 VALUES ('BBB'), ('BBBBB');

      DECLARE @SQL NVARCHAR(MAX) = 'SELECT ';

      SELECT @SQL = @SQL +
      N'(SELECT MAX(LEN(' + --You can also add ISNULL([Col],0) to get 0
      QUOTENAME(c.name) + ')) FROM '+
      QUOTENAME(t.name) + ') AS ' +
      QUOTENAME(t.name + '.'+c.name) + ', '
      FROM sys.columns c
      JOIN sys.tables t ON c.object_id = t.object_id
      WHERE c.name LIKE 'site%';

      SET @SQL = LEFT(@SQL, LEN(@SQL)-1);

      EXEC sp_executesql @SQL;


      Which will returns:



      +----------+----------+
      | T1.Site1 | T2.Site2 |
      +----------+----------+
      | 2 | 5 |
      +----------+----------+


      Live Demo






      share|improve this answer



























        3












        3








        3







        I don't understand what are you really trying to do, but I think you want something like



        CREATE TABLE T1(
        Site1 VARCHAR(45)
        );
        CREATE TABLE T2(
        Site2 VARCHAR(45)
        );

        INSERT INTO T1 VALUES ('A'), ('AA');
        INSERT INTO T2 VALUES ('BBB'), ('BBBBB');

        DECLARE @SQL NVARCHAR(MAX) = 'SELECT ';

        SELECT @SQL = @SQL +
        N'(SELECT MAX(LEN(' + --You can also add ISNULL([Col],0) to get 0
        QUOTENAME(c.name) + ')) FROM '+
        QUOTENAME(t.name) + ') AS ' +
        QUOTENAME(t.name + '.'+c.name) + ', '
        FROM sys.columns c
        JOIN sys.tables t ON c.object_id = t.object_id
        WHERE c.name LIKE 'site%';

        SET @SQL = LEFT(@SQL, LEN(@SQL)-1);

        EXEC sp_executesql @SQL;


        Which will returns:



        +----------+----------+
        | T1.Site1 | T2.Site2 |
        +----------+----------+
        | 2 | 5 |
        +----------+----------+


        Live Demo






        share|improve this answer















        I don't understand what are you really trying to do, but I think you want something like



        CREATE TABLE T1(
        Site1 VARCHAR(45)
        );
        CREATE TABLE T2(
        Site2 VARCHAR(45)
        );

        INSERT INTO T1 VALUES ('A'), ('AA');
        INSERT INTO T2 VALUES ('BBB'), ('BBBBB');

        DECLARE @SQL NVARCHAR(MAX) = 'SELECT ';

        SELECT @SQL = @SQL +
        N'(SELECT MAX(LEN(' + --You can also add ISNULL([Col],0) to get 0
        QUOTENAME(c.name) + ')) FROM '+
        QUOTENAME(t.name) + ') AS ' +
        QUOTENAME(t.name + '.'+c.name) + ', '
        FROM sys.columns c
        JOIN sys.tables t ON c.object_id = t.object_id
        WHERE c.name LIKE 'site%';

        SET @SQL = LEFT(@SQL, LEN(@SQL)-1);

        EXEC sp_executesql @SQL;


        Which will returns:



        +----------+----------+
        | T1.Site1 | T2.Site2 |
        +----------+----------+
        | 2 | 5 |
        +----------+----------+


        Live Demo







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 25 at 8:10

























        answered Mar 25 at 8:05









        SamiSami

        10.5k31645




        10.5k31645























            0














            Try this:You will get individual Scripts to execute.



            select 'select Max(len('+COLUMN_NAME+')),'''+COLUMN_NAME+ ''' as ColumnName ,'''+TABLE_NAME+''' as TableName from ' +table_name 
            from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME = 'YourColumnName'





            share|improve this answer























            • sorry i dont really get you

              – MichaelJ
              Mar 25 at 7:52











            • @MichaelJ The above code will get you the scripts which u have to execute in a loop to get the details of the Length of Column , Column Name and Table Name. Replace 'YourColumnName' with what ever column you are looking for.

              – Srikar mogaliraju
              Mar 25 at 9:22















            0














            Try this:You will get individual Scripts to execute.



            select 'select Max(len('+COLUMN_NAME+')),'''+COLUMN_NAME+ ''' as ColumnName ,'''+TABLE_NAME+''' as TableName from ' +table_name 
            from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME = 'YourColumnName'





            share|improve this answer























            • sorry i dont really get you

              – MichaelJ
              Mar 25 at 7:52











            • @MichaelJ The above code will get you the scripts which u have to execute in a loop to get the details of the Length of Column , Column Name and Table Name. Replace 'YourColumnName' with what ever column you are looking for.

              – Srikar mogaliraju
              Mar 25 at 9:22













            0












            0








            0







            Try this:You will get individual Scripts to execute.



            select 'select Max(len('+COLUMN_NAME+')),'''+COLUMN_NAME+ ''' as ColumnName ,'''+TABLE_NAME+''' as TableName from ' +table_name 
            from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME = 'YourColumnName'





            share|improve this answer













            Try this:You will get individual Scripts to execute.



            select 'select Max(len('+COLUMN_NAME+')),'''+COLUMN_NAME+ ''' as ColumnName ,'''+TABLE_NAME+''' as TableName from ' +table_name 
            from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME = 'YourColumnName'






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 at 7:49









            Srikar mogalirajuSrikar mogaliraju

            25317




            25317












            • sorry i dont really get you

              – MichaelJ
              Mar 25 at 7:52











            • @MichaelJ The above code will get you the scripts which u have to execute in a loop to get the details of the Length of Column , Column Name and Table Name. Replace 'YourColumnName' with what ever column you are looking for.

              – Srikar mogaliraju
              Mar 25 at 9:22

















            • sorry i dont really get you

              – MichaelJ
              Mar 25 at 7:52











            • @MichaelJ The above code will get you the scripts which u have to execute in a loop to get the details of the Length of Column , Column Name and Table Name. Replace 'YourColumnName' with what ever column you are looking for.

              – Srikar mogaliraju
              Mar 25 at 9:22
















            sorry i dont really get you

            – MichaelJ
            Mar 25 at 7:52





            sorry i dont really get you

            – MichaelJ
            Mar 25 at 7:52













            @MichaelJ The above code will get you the scripts which u have to execute in a loop to get the details of the Length of Column , Column Name and Table Name. Replace 'YourColumnName' with what ever column you are looking for.

            – Srikar mogaliraju
            Mar 25 at 9:22





            @MichaelJ The above code will get you the scripts which u have to execute in a loop to get the details of the Length of Column , Column Name and Table Name. Replace 'YourColumnName' with what ever column you are looking for.

            – Srikar mogaliraju
            Mar 25 at 9:22











            0














            If I understand your question, you may try to generate a dynamic SQL statement and execute this statement:



            -- Declarations
            DECLARE @stm nvarchar(max)
            SET @stm = N''

            -- Dynamic SQL
            SELECT @stm = (
            SELECT CONCAT(
            N'UNION ALL ',
            N'SELECT ''',
            t.name,
            N''' AS TableName, ''',
            c.name,
            N''' AS ColumnName, ',
            N'ValueLength = (SELECT MAX(LEN(',
            QUOTENAME(c.name),
            ')) FROM ',
            QUOTENAME(t.name),
            N')'
            )
            FROM sys.columns c
            JOIN sys.tables t ON c.object_id = t.object_id
            WHERE c.name LIKE 'site%'
            ORDER BY t.name, c.name
            FOR XML PATH('')
            )
            SET @stm = STUFF(@stm, 1, 10, N'')

            -- Execution
            PRINT @stm
            EXEC sp_executesql @stm





            share|improve this answer























            • You are right sir, that is why i am looking for.

              – MichaelJ
              Mar 25 at 8:29















            0














            If I understand your question, you may try to generate a dynamic SQL statement and execute this statement:



            -- Declarations
            DECLARE @stm nvarchar(max)
            SET @stm = N''

            -- Dynamic SQL
            SELECT @stm = (
            SELECT CONCAT(
            N'UNION ALL ',
            N'SELECT ''',
            t.name,
            N''' AS TableName, ''',
            c.name,
            N''' AS ColumnName, ',
            N'ValueLength = (SELECT MAX(LEN(',
            QUOTENAME(c.name),
            ')) FROM ',
            QUOTENAME(t.name),
            N')'
            )
            FROM sys.columns c
            JOIN sys.tables t ON c.object_id = t.object_id
            WHERE c.name LIKE 'site%'
            ORDER BY t.name, c.name
            FOR XML PATH('')
            )
            SET @stm = STUFF(@stm, 1, 10, N'')

            -- Execution
            PRINT @stm
            EXEC sp_executesql @stm





            share|improve this answer























            • You are right sir, that is why i am looking for.

              – MichaelJ
              Mar 25 at 8:29













            0












            0








            0







            If I understand your question, you may try to generate a dynamic SQL statement and execute this statement:



            -- Declarations
            DECLARE @stm nvarchar(max)
            SET @stm = N''

            -- Dynamic SQL
            SELECT @stm = (
            SELECT CONCAT(
            N'UNION ALL ',
            N'SELECT ''',
            t.name,
            N''' AS TableName, ''',
            c.name,
            N''' AS ColumnName, ',
            N'ValueLength = (SELECT MAX(LEN(',
            QUOTENAME(c.name),
            ')) FROM ',
            QUOTENAME(t.name),
            N')'
            )
            FROM sys.columns c
            JOIN sys.tables t ON c.object_id = t.object_id
            WHERE c.name LIKE 'site%'
            ORDER BY t.name, c.name
            FOR XML PATH('')
            )
            SET @stm = STUFF(@stm, 1, 10, N'')

            -- Execution
            PRINT @stm
            EXEC sp_executesql @stm





            share|improve this answer













            If I understand your question, you may try to generate a dynamic SQL statement and execute this statement:



            -- Declarations
            DECLARE @stm nvarchar(max)
            SET @stm = N''

            -- Dynamic SQL
            SELECT @stm = (
            SELECT CONCAT(
            N'UNION ALL ',
            N'SELECT ''',
            t.name,
            N''' AS TableName, ''',
            c.name,
            N''' AS ColumnName, ',
            N'ValueLength = (SELECT MAX(LEN(',
            QUOTENAME(c.name),
            ')) FROM ',
            QUOTENAME(t.name),
            N')'
            )
            FROM sys.columns c
            JOIN sys.tables t ON c.object_id = t.object_id
            WHERE c.name LIKE 'site%'
            ORDER BY t.name, c.name
            FOR XML PATH('')
            )
            SET @stm = STUFF(@stm, 1, 10, N'')

            -- Execution
            PRINT @stm
            EXEC sp_executesql @stm






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 25 at 8:07









            ZhorovZhorov

            6,8362824




            6,8362824












            • You are right sir, that is why i am looking for.

              – MichaelJ
              Mar 25 at 8:29

















            • You are right sir, that is why i am looking for.

              – MichaelJ
              Mar 25 at 8:29
















            You are right sir, that is why i am looking for.

            – MichaelJ
            Mar 25 at 8:29





            You are right sir, that is why i am looking for.

            – MichaelJ
            Mar 25 at 8:29

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333130%2fhow-to-get-the-length-one-column-in-all-tables-in-one-database%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해