How to change prefix table in SQL Server? - sql-server

I have DataBase Name: PMKIT, prefix Table : PMKIT.TableName.I want rename PMKIT.TableName to DBO.TableName. Can you help me!

You need to transfer your table from PMKIT schema to dbo schema:
ALTER SCHEMA dbo TRANSFER PMKIT.TableName;
Read more here: https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-schema-transact-sql?view=sql-server-2017
Or you can follow these steps to perform the same action via Management Studio user interface
Right click on your table and select Design
In Design view, open the properties window(Simply hit the F4 key on keyboard)
Find the Schema property and change it
Save your changes, and close the Design view

Related

How to Drop user from Netezza

How to drop user from netezza database?
I am trying to drop user name from netezza using below query
DROP USER 'mxy';
but it's giving me error like "You can't remove 'mxy' user because user contains objects"
'mxy' user create one user with his own schema object "mxy.jey'
How to remove user created object and as well 'mxy' user?
User "mxy" have some table object like mxy.example table so i couldn't delete the mxy user from the Netezza database so i changed the table schema to system admin user account and now i am able to remove "mxy" user from Netezza database.

How to change the owner of a SQL Server table from domain\username to dbo?

When I create a table, the owner is always domain\username instead of dbo. For example, domain\username.tablename I know how how to change it to dbo but what should I change in the configuration level to make sure that when I create a table, the default owner is dbo. like dbo.tablename ?
Thanks
You can change the DEFAULT SCHEMA via the Object Explorer
Security > Users > {Your User}
{right-click} > Properties
Then on the General Tab set Default schema
This can also be done using the T-SQL statement below:
ALTER USER [Domain\UserName] WITH DEFAULT_SCHEMA=[dbo]
Follow this steps:
In the Object Explorer, expand your database node, go to "Security" folder and expend that node too.
You will see "Users" folder, expend that node too to see the users.
Right click on your user
Click propertise from the menu appears.
In general tab, you will see "Default Schema", click on the button "..." on the right
Select "dbo" schema and click "OK" button.
Now, try to create a new table.

in SQL Server 2014 why SELECT * FROM System_User doesn't work but SELECT * FROM [ProjectManage].[dbo].[System_User] work

I am using SQL Server 2014 management studio, I found a strange situation.
in a SQL query dialog, I key in the below SQL:
SELECT * FROM System_User
I can see the table name in resource management dialog is: dbo.System_User
Then when I try to execute it, it said there is some grammar error.
If I change the SQL as:
SELECT * FROM [ProjectManage].[dbo].[System_User]
it works well.
But acutally in same SQL query dialog, I have another SQL:
SELECT * FROM FlowTemplateTransition
and its table name is dbo.FlowTemplateTransition in resource management dialog.
My question is:
what is the difference between dbo.FlowTemplateTransition and FlowTemplateTransition?
when do I need to add dbo and when it is unnecessary?
do I need to using square brackets always?
Thanks
dbo is the default schema in SQL Server. You can create your own schemas to allow you to better manage your object namespace.
In SQL Server Management Studio, you can create your own schema by browsing to Databases - Your Database - Security - Schemas. Or you can execute below query to create a schema.
CREATE SCHEMA [SchemaName] AUTHORIZATION [dbo]
You can use them to logically group your tables, for example by creating a schama for "vendors" information and another for "customers" data. Your tables would then display as:
vendors.BankAccounts
vendors.Transactions
customers.Address
Instead of using the default schema of dbo.
No need to use the square brackets[] always. But if your database or table name contains something like a dot(.) then you must use [].
As you have 3 questions. I have list it down separately.
Why SELECT * FROM System_User not working?
what is the difference between dbo.FlowTemplateTransition and FlowTemplateTransition
when do I need to add dbo and when it is unnecessary? do I need to using square brackets always?
Answer 1 : System_User is sql server built in function. Your table name conflict with this function that is why it gives an error.
Answer 2 : dbo is default database owner. If you don't write owner of table than Sql Server automatically consider dbo as an owner for that table.
Answer 3 : Generally dbo is not necessary to add.
The brackets are required if you use keywords or special chars in the table name.

How can i import indexes into ms SQL Server?

I created a new databases , and added tables using the import data wizard. But the wizard din't create the indexed and constraint's on the table. How can I Import indexes?
If your source is also SQL Server, you should be able to run Tasks -> Generate Scripts and select "Script Indexes" in the list of options for the old database and execute the script on the new database with maybe a change in database name.
Just manually add indexes to your table
Here is an example from MSDN:
This example creates an index on the au_id column of the authors table.
SET NOCOUNT OFF
USE pubs
IF EXISTS (SELECT name FROM sysindexes
WHERE name = 'au_id_ind')
DROP INDEX authors.au_id_ind
GO
USE pubs
CREATE INDEX au_id_ind
ON authors (au_id)
GO
The other way you can do this is open the table in design mode management studio, highlight the field you want to index and look at the options at the top. One of them is for indexes and you can simply manually add it and give it a name right in management studio.

default schema synonym

I have a database FooDb with a schema BarSchema that contains a table Tbl (i.e. FooDb.BarSchema.Tbl)
I am also logged in as a user with BarSchema as default.
This query works fine
SELECT * FROM FooDb..Tbl
I also have a synonym for this table in another db
CREATE SYNONYM TblSynonym FOR FooDb..Tbl
But now I get an error "Invalid object name 'FooDb..Tbl'" when executing
SELECT * FROM TblSynonym
If i change the synonym to
CREATE SYNONYM TblSynonym FOR FooDb.BarSchema.Tbl
it works fine.
Why doesn't the default schema work in synonyms?
(The background is that I'm consoldating data from several databases which all got same table names but different schema names. It would be a lot easier if I could set the default schema for each database on the user and then ignore it everywhere in the script)
The documentation suggests the db..tbl syntax should work:
schema_name_2 Is the name of the
schema of the base object. If
schema_name is not specified the
default schema of the current user is
used.
This works for me in SQL Server 2008:
create synonym TestSynonym for TestDB..TestTable
One cause might be that the default schema is associated with the user, not the database. Check if your user has an unexpected default schema? In my SSMS, that setting is located under Database -> Security -> Users -> Properties.

Resources