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

Time:06-14

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:

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

 

CodePudding user response:

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');
  • Related