Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for SQL server #3

Open
jpresutti opened this issue Apr 27, 2021 · 1 comment
Open

Add support for SQL server #3

jpresutti opened this issue Apr 27, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@jpresutti
Copy link
Contributor

No description provided.

@jpresutti jpresutti added the enhancement New feature or request label Apr 27, 2021
@jpresutti jpresutti added this to the v1.6.0 milestone Apr 27, 2021
@jpresutti jpresutti self-assigned this Apr 27, 2021
@jpresutti jpresutti modified the milestones: v1.6.0, v2.0.0 Apr 28, 2021
@jpresutti jpresutti removed this from the v2.0.0 milestone Oct 24, 2021
@jpresutti jpresutti modified the milestone: v3.0.0 Jun 9, 2022
@alevyinroc
Copy link

Give this a look as a SQL Server version of desc tablename in MySQL

select C.[name] as [Field]
, concat(TY.[name],
case when TY.name in ('int','bigint','smallint','tinyint','bit') then NULL
when TY.[name] in ('decimal','numeric')then concat('(',cast(C.precision as varchar),',',cast(C.scale as varchar),')')
when TY.[name] in ('money','smallmoney')  then NULL
when TY.[name] in ('float') then concat('(',cast(C.precision as varchar),')')
when TY.[name] in ('real') then NULL 
when TY.[name] in ('nchar','nvarchar')    then concat('(',cast(C.max_length/2 as varchar),')')
when TY.[name] in ('char','varchar')      then concat('(',cast(C.max_length as varchar),')')
when TY.[name] in ('date','datetime','smalldatetime') then NULL
when TY.[name] in ('time') then concat('(',cast(C.scale as varchar),')')
when TY.[name] in ('datetime2','datetimeoffset') then concat('(',cast(C.scale as varchar),')')
when TY.[name] in ('text','ntext','image') then NULL
when TY.[name] in ('binary','varbinary') then concat('(',cast(C.max_length as varchar),')')
else TY.[name]
end) as [Type]
, case when C.is_nullable =1 then 'Yes' else 'No' end as [NULL]
, case when (IC.column_id is not null) then 'PRI' else '' end as 'Key'
, DC.definition as [Default]
, case when C.is_identity = 1 then 'auto_increment' end as [extra]
from sys.tables as T
join sys.schemas as S on T.schema_id = S.schema_id
    join sys.columns as C on T.object_id = C.object_id
    join sys.types as TY on TY.user_type_id = C.user_type_id
    left outer join sys.indexes I on T.object_id=I.object_id and I.is_primary_key = 1
    left outer join sys.index_columns IC on I.object_id=IC.object_id and IC.OBJECT_id = T.object_id
        and I.index_id=IC.index_id and C.column_id = IC.column_id
    left outer join sys.default_constraints as DC on DC.parent_object_id = T.object_id and DC.parent_column_id = C.column_id and DC.type = 'D'
where
	T.name = 'TABLENAME'
    and S.[name] = 'SCHEMANAME'
order by C.column_id asc;

MSSQL data types: https://learn.microsoft.com/en-us/sql/t-sql/data-types/data-types-transact-sql?view=sql-server-ver16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants