SQL Server System stored procedures

Source: Internet
Author: User

exec sp_databases; --View Database
exec sp_tables; --View Table
EXEC sp_columns categories;--view columns
EXEC sp_helpindex categories;--View index
EXEC sp_helpconstraint categories;--constraints
exec sp_stored_procedures;
exec sp_helptext ' sp_stored_procedures ';--view stored procedure creation, definition statement
EXEC sp_rename Student, stuinfo;--modify the name of the table, index, column
exec sp_renamedb mytempdb, mydb;--change database name
exec sp_defaultdb ' master ', ' MyDB ';--Change the default database for logins
EXEC sp_helpdb;--database help, querying database information
exec sp_helpdb master;

--Query the number of rows in the database, the allocated capacity, the capacity used for the data, and the index usage capacity

IF object_id (' tempdb.. #temp ') is not NULL
BEGIN
DROP TABLE #temp
END

CREATE TABLE #temp
(
name varchar,
rows INT,
reserved varchar),
Data VARCHAR,
Inde X_size varchar,
unused varchar ()

)

DECLARE @tablename varchar (+)
DECLARE @sql varchar (
DECLARE @str VARCHAR
DECLARE tablecursor CURSOR
for
SELECT name
from sysobjects
WHERE Xtype = ' u '
OPEN tablecursor
FETCH NEXT from Tablecursor to @tablename
while @ @fetch_status = 0
BEGIN
Set @str = @tablename
SET @sql = ' INSERT into #temp exec sp_spaceused ' + @tablename
Exec (@sql)
FETCH NEXT F ROM tablecursor to @tablename
END
CLOSE tablecursor
deallocate tablecursor
SELECT *
from #temp

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.