[英]What does double dots .. mean in SQL Server?
I am using SQL Server.我正在使用 SQL 服务器。 I found the following way to backup a database table:
我找到了以下备份数据库表的方法:
-- Taking a backup
SELECT * INTO MY_BACKUP_DATABASE..CustomersTemporaryTable FROM Customers
I am trying to understand the ..
in the syntax.我试图理解语法中的
..
。 From what I understand, the sentence means that Customers
is the table that is going to be backed-up by placing it all of its content into the database called MY_BACKUP_DATABASE
using CustomersTemporaryTable
as the destination table.据我了解,这句话的意思是,
Customers
是要备份的表,方法是将其所有内容放入名为MY_BACKUP_DATABASE
的数据库中,使用CustomersTemporaryTable
作为目标表。 I assume when executing the sentence, CustomersTemporaryTable
must already exist.我假设在执行这句话时,
CustomersTemporaryTable
必须已经存在。 Is my understanding of the sentence to take a backup correct?我对备份句子的理解是否正确?
First of all, understand that what you are doing is not "taking a backup", it is inserting data into a table from another table.首先,要了解您所做的不是“进行备份”,而是将数据从另一个表插入到一个表中。 If you have not created the destination table the syntax is like this:
如果您尚未创建目标表,则语法如下:
Select * INTO Destination_Table FROM Source_Table Select * INTO Destination_Table FROM Source_Table
The destination table will be created automatically.目标表将自动创建。 This doesn't necessarily work so well if you will be inserting additional data that might be different lengths or data types, but for a one of select should work fine.
如果您要插入可能是不同长度或数据类型的其他数据,这不一定能很好地工作,但对于 select 之一应该可以正常工作。
Each MS SQL Table identifiers can have a name compound of three parts separates with a dot:每个 MS SQL 表标识符可以有一个由三个部分组成的名称复合,用点分隔:
Syntax:句法:
db_name.schema_name.table_name
But it is not always necessary to specify the three parts.但并不总是需要指定这三个部分。
Inside the current database, no need to specify the db_name.在当前数据库中,无需指定 db_name。 It's implicit... By default every SQL user is associate with a specific default schema (frequently dbo too...).
它是隐含的......默认情况下,每个 SQL 用户都与特定的默认架构相关联(通常也是 dbo ......)。
So you can specify a table name with:因此,您可以使用以下命令指定表名:
schema_name.table_name
...SQL Server will try to find the table into the current DB ...SQL 服务器将尝试将表查找到当前数据库中
db_name..table_name
...SQL Server will try to find the table into the specified DB and the default user schema ...SQL 服务器会尝试在指定的DB和默认用户模式中查找表
table_name
...SQL Server will try to find the table into the current DB and the default user schema ...SQL 服务器将尝试将表查找到当前数据库和默认用户架构中
To know with SQL schema is associated with your SQL user, use:要知道 SQL 模式与您的 SQL 用户相关联,请使用:
SELECT SCHEMA_NAME() AS DEFAULT_CURRENT_USER_SCHEMA
To know all the associations between SQL users and SQL schemas, do:要了解 SQL 用户和 SQL 模式之间的所有关联,请执行以下操作:
SELECT name AS USER_NAME, default_schema_name
FROM sys.database_principals
WHERE type_desc LIKE '%?_USER' ESCAPE '?'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.