Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to insert column name of one table to row of another table with some added property

Suppose i have a table A with columns :

| Name | IsNUllable  | Datatype |

And another table B

 | id | Stock | Power

i want to make an entry to a table A by taking the column Name of Table B and adding property to it
example:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

| Name | IsNUllable  | Datatype |
|  id  |  False      | int      |
|Stock |  False      | float    |
|power |  False      | nvarchar |

 

>Solution :

There is no need to store this information, it’s already available in the sys objects. You can easily get this with a query like below:

SELECT c.[name],
       c.is_nullable,
       t.[name] AS Datatype
FROM sys.columns c
     JOIN sys.types t ON c.user_type_id = t.user_type_id
WHERE c.object_id = OBJECT_ID(N'dbo.YourTable');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading