New T-SQL Syntax

Published Mon, Jun 6 2005 21:08 | GregLow

Is this one T-SQL statement or two?

CREATE SCHEMA marketingdata AUTHORIZATION peter

CREATE TABLE products (RecID int IDENTITY(1,1), ProductName varchar(35))

Yep, you wouldn't be alone if you said “two“. But it's only one. Had this come up in the classes I've been running last week on SQL Server 2005 development. Some students highlighted it a line at a time, some ran the batch. The results are then different. If you run it as a batch, the table gets created in the new schema, otherwise it's in the default schema of the user executing the commands. Can't say I like the syntax but it's an example of the table definition clause (optional) in the CREATE SCHEMA statement. See more in Books Online under CREATE SCHEMA.