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

HOW to create sqlserver schema #738

Open
zhanghaiyang9999 opened this issue Apr 29, 2022 · 2 comments
Open

HOW to create sqlserver schema #738

zhanghaiyang9999 opened this issue Apr 29, 2022 · 2 comments

Comments

@zhanghaiyang9999
Copy link

I use the following codes to create schema, but always failed:
str_sql :=USE [test001]; GO CREATE SCHEMA [test3] GO
_,err := conn.Exec(str_sql)

always return the error:
CREATE SCHEMA' must be the first statement in a query batch.

Can anyone help this issue, thanks!

Describe the bug
A clear and concise description of what the bug is.

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message:
Stack trace:

To Reproduce
Include a complete code listing that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

Expected behavior
A clear and concise description of what you expected to happen.

Further technical details

SQL Server version: (e.g. SQL Server 2017)
Operating system: (e.g. Windows 2019, Ubuntu 18.04, macOS 10.13, Docker container)
Table schema

Additional context
Add any other context about the problem here.

@bokwoon95
Copy link

  1. Remove the GO statement. That is not valid SQL, it only works in SSMS.
  2. You cannot use CREATE SCHEMA together with other SQL statements (https://stackoverflow.com/q/5748056). Wrap it in EXEC().
conn.Exec("USE [test001]; EXEC('CREATE SCHEMA [test3]');")

@kardianos
Copy link
Collaborator

kardianos commented Oct 11, 2022 via email

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

No branches or pull requests

3 participants