Error En Comando Sql Select Db_id
Contents |
SERVER - A Quick Note on DB_ID() and DB_NAME() -
How To Find Database Id In Sql Server
Get Current Database ID - Get Current how to find object name from object id in sql server Database Name January 13, 2011Pinal DaveSQL, SQL Server, SQL Tips database id oracle and Tricks22 commentsQuite often a simple things makes experienced DBA to look for simple thing. Here are few
Sql Object Id
things which I used to get confused couple of years ago. Now I know it well and have no issue but recently I see one of the DBA getting confused when looking at the DBID
Db_name(dbid)
from one of the DMV and not able to related that directly to Database Name.-- Get Current DatabaseID
SELECT DB_ID() DatabaseID;
-- Get Current DatabaseName
SELECT DB_NAME() DatabaseName;
-- Get DatabaseName from DatabaseID
SELECT DB_NAME(4) DatabaseName;
-- Get DatabaseID from DatabaseName
SELECT DB_ID('tempdb') DatabaseID;
-- Get all DatabaseName and DBID
SELECT name,database_id
FROM sys.databases;
Reference: Pina
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft sql server get current database name Student Partners ISV Startups TechRewards Events Community Magazine Forums
How To Find Dbid In Oracle
Blogs Channel 9 Documentation APIs and reference Dev centers Retired content Samples We’re how to find database name in sql server sorry. The content you requested has been removed. You’ll be auto redirected in 1 second. Transact-SQL Reference (Database Engine) Built-in Functions (Transact-SQL) Metadata http://blog.sqlauthority.com/2011/01/13/sql-server-a-quick-note-on-db_id-and-db_name-get-current-database-id-get-current-database-name/ Functions (Transact-SQL) Metadata Functions (Transact-SQL) DB_ID (Transact-SQL) DB_ID (Transact-SQL) DB_ID (Transact-SQL) @@PROCID (Transact-SQL) APP_NAME (Transact-SQL) APPLOCK_MODE (Transact-SQL) APPLOCK_TEST (Transact-SQL) ASSEMBLYPROPERTY (Transact-SQL) COL_LENGTH (Transact-SQL) COL_NAME (Transact-SQL) COLUMNPROPERTY (Transact-SQL) DATABASE_PRINCIPAL_ID (Transact-SQL) DATABASEPROPERTYEX (Transact-SQL) DB_ID (Transact-SQL) DB_NAME (Transact-SQL) FILE_ID (Transact-SQL) FILE_IDEX (Transact-SQL) FILE_NAME (Transact-SQL) FILEGROUP_ID (Transact-SQL) FILEGROUP_NAME (Transact-SQL) FILEGROUPPROPERTY https://msdn.microsoft.com/en-us/library/ms186274.aspx (Transact-SQL) FILEPROPERTY (Transact-SQL) FULLTEXTCATALOGPROPERTY (Transact-SQL) FULLTEXTSERVICEPROPERTY (Transact-SQL) INDEX_COL (Transact-SQL) INDEXKEY_PROPERTY (Transact-SQL) INDEXPROPERTY (Transact-SQL) NEXT VALUE FOR (Transact-SQL) OBJECT_DEFINITION (Transact-SQL) OBJECT_ID (Transact-SQL) OBJECT_NAME (Transact-SQL) OBJECT_SCHEMA_NAME (Transact-SQL) OBJECTPROPERTY (Transact-SQL) OBJECTPROPERTYEX (Transact-SQL) ORIGINAL_DB_NAME (Transact-SQL) PARSENAME (Transact-SQL) SCHEMA_ID (Transact-SQL) SCHEMA_NAME (Transact-SQL) SCOPE_IDENTITY (Transact-SQL) SERVERPROPERTY (Transact-SQL) STATS_DATE (Transact-SQL) TYPE_ID (Transact-SQL) TYPE_NAME (Transact-SQL) TYPEPROPERTY (Transact-SQL) VERSION (Transact-SQL) TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. DB_ID (Transact-SQL) Other Versions SQL Server 2012 THIS TOPIC APPLIES TO: SQL Server (starting with 2008)Azure SQL DatabaseAzure SQL Data Warehouse Parallel Data Warehouse Returns the database identification (ID) number. Transact-SQL Syntax ConventionsSyntax Copy -- Syntax for SQL Server, Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse DB_ID ( [ 'database_name' ] ) Argume
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the http://stackoverflow.com/questions/18014392/select-sql-server-database-size company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Select SQL Server database size up vote 64 down vote favorite 24 how can i query my sql server to how to only get the size of database? I used this : use "MY_DB" exec sp_spaceused I got this : database_name database_size unallocated space My_DB 17899.13 MB 5309.39 MB It returns me several column that i don't need, maybe there is a trick to select database_size column from this stored procedure ? I also tried this code : SELECT DB_NAME(database_id) AS DatabaseName, Name AS Logical_Name, Physical_Name, (size * 8) / 1024 SizeMB FROM sys.master_files WHERE DB_NAME(database_id) how to find = 'MY_DB' It gives me this result: DatabaseName Logical_Name Physical_Name SizeMB MY_DB MY_DB D:\MSSQL\Data\MY_DB.mdf 10613 MY_DB MY_DB_log D:\MSSQL\Data\MY_DB.ldf 7286 So i wrote this: SELECT SUM(SizeMB) FROM ( SELECT DB_NAME(database_id) AS DatabaseName, Name AS Logical_Name, Physical_Name, (size * 8) / 1024 SizeMB FROM sys.master_files WHERE DB_NAME(database_id) = 'MY_DB' ) AS TEMP I got: 1183 So it works but maybe there is a proper way to get this? sql sql-server sql-server-2008 sql-server-2008-r2 share|improve this question edited Feb 12 at 8:20 Devart 76.4k12100120 asked Aug 2 '13 at 10:12 Adeel ASIF 7362925 2 same result would be with this 'SELECT SUM((size*8)/1024) SizeMB FROM sys.master_files WHERE DB_NAME(database_id) = 'YOUR_DB'' –sickUnit Aug 2 '13 at 10:21 @LittlBobbyTables How can i add MB in the column? I want "MB" after the value –Adeel ASIF Aug 2 '13 at 13:51 add a comment| 4 Answers 4 active oldest votes up vote 90 down vote accepted Try this one - Query: SELECT database_name = DB_NAME(database_id) , log_size_mb = CAST(SUM(CASE WHEN type_desc = 'LOG' THEN size END) * 8. / 1024 AS DECIMAL(8,2)) , row_size_mb = CAST(SUM(CASE WHEN type_desc = 'ROWS' THEN size END) * 8. / 1024 AS DECIMAL(8,2)) , total_size_mb = CAST(SUM(size) * 8. / 1024 AS DECIMAL(8,2)) FROM sys.master_files WITH(NOWAIT) WHERE database_id = DB_ID() -- for current db GROUP BY data