You are on page 1of 2

/**

* Show all tables from a database.

*/

Ans:

-- mysql

Show tables.

-- sql server
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE';
SELECT * FROM <databse_name>.INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'

/**

* Convert data type from one to another.

*/

Ans:

-- mysql

CAST(value as datatype), convert(value, type)

Select CAST( ‘20200101’ as DATE);

SELECT CONVERT("14:06:10", TIME);

- - Sql server

CAST(value as datatype), convert(type, value)

Select CAST( ‘20200101’ as DATE);

SELECT CONVERT(TIME, "14:06:10");

-- Error handling

Try_cast(),

try_convert().
/**

* Database diagrams problem: SQL Server principal “dbo” does not exist,

*/

Ans:

-- SQL server

Programmatically: use [YourDatabaseName] EXEC sp_changedbowner 'sa';

USE [<dbname>]

GO

sp_changedbowner '<user>'

Graphically: Database right click-->properties-->files-->select database owner-->select [sa]-- ok

You might also like