I am trying to build Visual Studio solution for Azure SQL Database.
I have SQL script with CREATE TABLE
and its extended attributes:
create table schema.table_name (
table_name_Key integer not null,
constraint PK_table_Name primary key (table_Name_Key, Some_Column)
)
go
if exists (select 1 from sys.extended_properties
where major_id = object_id('table_name') and minor_id = 0)
begin
execute sp_dropextendedproperty 'MS_Description',
'user', 'schema', 'table', 'table_name' ;
end
execute sp_addextendedproperty 'MS_Description',
'This table will be used for ....',
'user', 'schema', 'table', 'table_name';
go
if exists (select 1 from sys.extended_properties p
where p.major_id = object_id('table_name')
and p.minor_id = (select c.column_id from sys.columns c
where c.object_id = p.major_id
and c.name = 'table_name_Key'))
begin
execute sp_dropextendedproperty 'MS_Description',
'user', 'schema', 'table', 'table_name', 'column', 'table_name_Key';
end
execute sp_addextendedproperty 'MS_Description',
'Primary Key of table_name table',
'user', 'schema', 'table', 'table_name', 'column', 'table_name_Key';
go
I am still getting errors when building that I am missing batch delimiter:
Error SQL71006: Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.
What am I missing and where? I already tried to add go
after end
but still error.
If you are using SQL Server Data Tools (SSDT) database projects in Visual Studio then you need to think about things differently (and work through some of the tutorials , or this one ).
Basically each object is held in a single script and you do not have to write conditional statements (like IF EXISTS...
). You simply define the object as you want it and SqlPackage.exe works out at deploy-time what the definition should be.
A simple table with one extended property:
CREATE TABLE [testSchema].[table_name] (
[table_name_Key] INT NOT NULL,
[Some_Column] VARCHAR (10) NOT NULL,
CONSTRAINT [PK_table_Name] PRIMARY KEY CLUSTERED ([table_name_Key] ASC, [Some_Column] ASC)
);
GO
EXECUTE sp_addextendedproperty @name = N'Caption', @value = 'Some_column is a required column.', @level0type = N'SCHEMA', @level0name = N'testSchema', @level1type = N'TABLE', @level1name = N'table_name', @level2type = N'COLUMN', @level2name = N'Some_Column';
Define your table in a similar manner to above, press Build and work through the errors.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.