Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Creating multiple views in SQL Server 2008 database through sqlcmd

$
0
0

I've written a script that generates a ddl file. The ddl file contains all the table creation, view creation and stored proc creation SQL statements for refreshing my database. The ddl file gets run by sqlcmd.

From reading other forum posts, it seems that views and stored procedures can only be created through the sqlcmd command when they are part of an individual batch. Can someone please direct me to the documentation on how to do this?

My DDL is below pertaining to view creation:

CREATE VIEW [global].[viewDstLocations]
  WITH SCHEMABINDING
 AS
   SELECT REPLACE(STR(c.dstYear, 2), ' ', '0') AS 'DSTyear',
          a.countryCode AS 'CountryCode',
          a.countryDivision AS 'CountryDivision',
          a.stateCode AS 'StateCode',
          a.locationCode AS 'LocationCode',
          a.locationType AS 'LocationType',
          a.gmtVariation AS 'GMTvariation',
          c.dstVariation AS 'DSTvariation',
          REPLACE(SUBSTRING(CONVERT(VARCHAR(8), c.dstStartTs, 8), 1, 5), ':', '')  AS 'DSTstart_time',
          CONVERT(VARCHAR(8), c.dstStartTs, 12) AS 'DSTstart_date',
          c.statusMarkerStart AS 'StatusMarker_start',
          REPLACE(SUBSTRING(CONVERT(VARCHAR(8), c.dstEndTs, 8), 1, 5), ':', '')  AS 'DSTend_time',
          CONVERT(VARCHAR(8), c.dstEndTs, 12) AS 'DSTend_date',
          c.statusMarkerEnd AS 'StatusMarker_end',
          c.dataIndicator AS 'DataIndicator',
          b.locationName AS 'LocationName',
          a.latitude AS 'Latitude',
          a.longtitude AS 'Longtitude'
      FROM [global].[dstLocations] a
         LEFT JOIN [global].[dstLocationNames] b ON (b.locationId = a.locationId AND b.locale = 'en_US')
            LEFT JOIN [global].[dstLocationInfo] c ON (c.locationId = a.locationId);

GO;

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'DST location info shown in the legacy table structure as well as data format.',
 @level0type=N'SCHEMA', @level0name=N'global', @level1type=N'VIEW', @level1name=N'viewDstLocations';

GO;

CREATE VIEW [global].[viewTypes]
  WITH SCHEMABINDING
 AS
   SELECT a.levelTypeId, a.levelTypeName, a.levelDepth, b.productId, b.productName, c.baseLevelTypeId, c.baseLevelTypeName
      FROM [global].[levelTypes] a
         LEFT JOIN [global].[products] b ON (b.levelTypeId = a.levelTypeId)
            LEFT JOIN [global].[baseLevelTypes] c ON (c.levelTypeId = a.levelTypeId);

GO;

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'Displays level types and their associated products and base level types.' , @level0type=N'SCHEMA',@level0name=N'global', @level1type=N'VIEW',@level1name=N'viewTypes';

GO;

<<Several other views>>


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>