SQL Query to get table/view column data types


You can use this to recreate a table based on a view/table:

DECLARE @TABLE VARCHAR(80) = ‘YOUR_TABLE_HERE’
SELECT COLUMN_NAME,
(
CASE WHEN CHARacter_maximum_length IS NOT NULL THEN UPPER(DATA_TYPE) + ‘(‘ + CAST(CHARacter_maximum_length AS VARCHAR(MAX)) + ‘)’
ELSE UPPER(DATA_TYPE) END
) DATA_TYPE
FROM information_schema.columns
WHERE TABLE_NAME = @TABLE

OR

If you want to just recreate the table do this:

SELECT * INTO TBL_TEMP FROM TABLE_NAME

Also to Cache data, do this:

TRUNCATE TABLE CACHE_TABLE_HERE
INSERT INTO CACHE_TABLE_HERE
SELECT * FROM SOURCE_DATA_TABLE_HERE
SELECT * FROM CACHE_TABLE_HERE

Categories: SharePoint or Custom Development | Leave a comment

Post navigation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: