CodeAlter Table Add constraint Foreign Key References on Delete Restrict on Update Restrict;(constraint can be appended with the constraint name)The reason for the error is that the IDs of the previous two tables are of different types, one when int, and one when bigintWorkaround when modifying the table,Alter Table bigint;You can change it after that.Here is
Tags: exec print object_id SQ Var variant objects Create LLDif exists(Select * fromsysobjectswhereId=object_id('Generatedata') and ObjectProperty(ID,'isprocedure')=1 ) Drop ProcedureGeneratedataGoCREATE PROCEDUREGeneratedata@tablenamesysname--table names under the same database as begin Declare @column varchar( -) Declare @columndata varchar( -) Declare @
each time. The ID seed is the initial value of the field. For example, 1, the value of this field in the first record is 1.
After setting, do not forget to click "save"
END
Notes
When setting an auto-increment field, pay attention to the field type. Not all field types can be set to auto-increment.
For tables with auto-incrementing primary keys in SQLServer, ID values cannot be specified directly. You can use the following method to insert data.
1. SQL
SQL Server lock table, unlock, and view sale table,
Lock a table in the database
Copy codeThe Code is as follows:SELECT * FROM table WITH (HOLDLOCK)
Note: What is the difference between locking a database
Lock a table in a database
The code is as follows
Copy Code
SELECT * from table with (HOLDLOCK)
Note: The difference between a table that locks a database
The code is as follows
Copy Code
SELECT * from table with (HOLDLOCK)
Other transactions
Tags: score create system identifier check common whitespace graphical ssmsKnowledge section1. SQL Server Data type• Data type is a property of the data used to define the data as time, number, string (text, letter), etc.· SQL Server provides a set of system data types that
How to determine the existence of a table or database in SQL server, but in actual use, you need to determine the Status bit:Some status bits can be set by the user using sp_dboption (read only, dbo use only, single user, etc:
1 = autoclose; Use sp_dboption to set. The database is completely closed, and its resources are released after the last user logs out.4 =
Server. When several tables must store the same data type, and to ensure that these columns have the same data type, length, and can be empty, you can use user-defined data types. For example, you can define a data type called postal_code, which is based on the char data type.When creating a user-defined data type, three data types must be provided: the data type name, the system data type based on, and the data type can be empty.(1)
intoScoreValues(3,'3-105', -)Insert intoScoreValues(4,'3-105', -)Insert intoScoreValues(5,'3-105', -)Insert intoScoreValues(6,'3-105', -)--Business: To ensure the complete implementation of the entire process, all without problems, unified submission, once there is a problem, back to the origin. Like bank transfers.Begin Tran--z The start of the transaction--start writing the process statement--After the statement is finishedIf @ @ERROR >0Rollback tran--ROLLBACK TRANSACTIONElseCommit Tran--
Lock a table in a database
Copy Code code as follows:
SELECT * from table with (HOLDLOCK)
Note: The difference between a table that locks a database
Copy Code code as follows:
SELECT * from table with (HOLDLOCK)
Other transactions can read the
TABNAME add primary key (COL)--delete primary key ALTER TABLE tabname drop p Rimary Key (COL)--Creating an index create [unique] index idxname on tabname (COL)--delete index drop indexes idxname/* create BBSDB database */use Masterif Exists (SELECT * from sysdatabases where name= ' bbsdb ') BeginPrint ' database has been created and cannot be recreated ' endelse
SQL Server DDL triggers (Trigger)-Create a database-level DDL triggerThe following invokes a trigger for a database when it is created, and writes the user account that created the data table to the event log in Windows.Create TRIGGER Reminderon databasefor create_tableasdeclare @str NVARCHAR (+) SET @str =suser_sname
SQL Server temporary table usage-- Delete temporary table # TMPCreate Table # TMP -- create a temporary table # TMP(Id int identity () not null, -- creates a column ID and Adds 1 to eac
this situation. I hope you have new discoveries in the actual work process, and provide us with information in time for further updates. 1.1 SQL Server database detection SQL Server provides commands for database detection, which can be used by DBCC CHECKDB to detect the allocation and structure of individual obje
Label:In auditing, it is sometimes necessary to modify the table structure of Oracle and then create the table structure in SQL Server, and then import the data into SQL Server, in the
the partition field Drop Index L_testresult. Idx_l_testresult_measuretime --Create an index by partition scheme CREATE INDEX Idx_l_testresult_measuretime On L_testresult (Measuretime) On Monthdaterangescheme (Measuretime) 6. For a clustered index in a partitioned table, it is best to remove the rebuild: --Rebuilding the main building of clustered index ALTER
server| Create | scripts | asynchronous | execute
Application Scenario:
Many complex update queries are time-consuming in a large database. In order to avoid the user waiting for a long time, those time-consuming operations can be performed asynchronously, immediately return the execution information to the user, while performing operations in the database background, wait until the completion of the data
SQL Server traversal tables are typically used in cursors, and SQL Server can easily loop through a cursor to implement SQL Server traversal of records in a table. This article will int
for this situation. I hope you have new discoveries in the actual work process, and provide us with information in time for further updates.1.1 Detection of SQL Server databasesSQL Server provides commands for database detection, which can be used by DBCC CHECKDB to detect the allocation and structure of individual objects in a database, and to display all error
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.