I. Basics
1. Description: Create a database
Create Database database-name
2. Description: delete a database.
Drop database dbname
3. Description: BackupSQLServer
--- Create a device for the backup data
Use master
Exec sp_addumpdevice
--/Step 2 *********** Delete the foreign key constraints of all tables ******************* ******/
Declare C1 Cursor For Select ' Alter table [ ' + Object_name (Parent_obj) + ' ] Drop constraint [ ' + Name + ' ]; ' From
Create Database book
Create Table Booker (Bookno int primary key not null,Bookname varchar (50) not null,Bookprice float not null,Bookcount int not null,Bookwriter varchar (50) not null)
Insert into Booker values (1, 'wang Xiaojing ', 'Li
Application background:
The table structure of the two databases is the same, but the table name prefix is different. Now, the ID of the original data table must not be imported.
It is not feasible to use the database batch import/export tool. You
1. encryption: Add the following sentence to the stored procedure:With Encryption
Example:Create proc bj_tixin_01@ I int output, --- 0 indicates that prompt 1 indicates cancellation prompt@ ER char (80) output,@ TT int outputWith EncryptionAsSet @
Declare
@ Viewname
Varchar
(
250
),
@ ID
Int
,
@ Text
Varchar
(
8000
)
Declare
# Aa
Cursor
For
Select
ID, name
From
Sysobjects
Where
Objectproperty
(ID,
'
Isview
'
)
=
1
The table structure is as follows:
Org_info
Org_id, org_parent_id, org_parent_path
The org_parent_path field must be updated. The field value is org_parent_path + '.' of the parent node + org_id of the parent node.
Ideas
First find the
Create
Procedure
Genforeignkey
@ Tablename
Varchar
(
200
)
--
Name of the table in the foreign key database to be added
As
Declare
@ Cur
Cursor
Declare
@ FK
Varchar
(
100
)
1. System Table sysobjects
Each object (such as constraints, default values, logs, rules, and stored procedures) created in the database corresponds to a row.
Column name
Data Type
Description
Name
Sysname
When I used the new SQL server2005 function to construct the paging storage process, I mentioned using the row_number () function to replace top to implement the paging storage process.
However, after a long time, we found a new problem, that is,
CopyCode The Code is as follows: declare cur cursor
Select
[Object_name] = S. Name + '.' + object_name (A. object_id ),
B. Name
From SYS. dm_db_index_physical_stats (db_id ('adventureworks'), null) as
Join SYS. indexes as B
On a. [object_id] = B.
Add SQL Server statements and stored procedures to favorites
-- ===================================================== ====================
-- List all SQL Server tables, field names, primary keys, types, lengths, decimal places, and other
Today, I wrote a complex SQL statement. The result shows that it does not meet the project requirements, but the syntax is worth learning.
Declare @ delid int -- the row to be deleted
Declare @ CID int
Set @ delid = '000000'
Begin
Restore the database to see the "no exclusive access" solution (killing the database connection Stored Procedure sqlserver), stored procedure sqlserver
The stored procedure for creating a master database is as follows:Createproc killspid (@
SQL Server database bcp export backup file application, serverbcp/*** Authorization*/EXEC sp_configure 'show advanced options', 1;GoReconfigure;GoExec sp_configure 'xp _ Your shell', 1;GoReconfigure;Go/** Import the text file of the specified table *
Find the current maximum id and Database id of all tables in the database.
Today, we need to count the current maximum IDs of all tables in the database. It is too difficult to query each table one by one, so we can write a stored procedure for
Database practical Script 1 --- query the table names with data in the database and the number of rows in the table, 1 --- number of rows
Create table # Temp(Name varchar (30 ),Num int)
Declare @ Name varchar (30)Declare @ SQL varchar (1000)
Copy codeThe Code is as follows: declare @ t varchar (255), @ c varchar (255)
Declare table_cursor cursor for select a. name, B. name
From sysobjects a, syscolumns B, policypes c
Where a. id = B. id and a. xtype = 'U' and c. name
In ('Char ',
A cursor provides you with a method to operate data in a table on a row-by-row basis instead of a result set.
1. How to use a cursor
1) define the Cursor statement Declare Cursor
2) create a cursor statement Open
3) extract the cursor column value
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.