Label:first, Getting started with SQL statements1. SQL statements are statements that are specific to the DBMS "talk", and the SQL syntax is recognized by different DBMS.2. The string in the SQL statement is enclosed in single quotation marks.3. SQL statements are insensitiv
Label:In writing SQL, we often encounter such a problem. Every time you insert, you have to judge whether the data table already exists in this data, the so-called same data, except the primary key all columns are the same, no insert, there is update. In this situation, we do not know whether this column exists, so the
* ** Filename: DropKeyAddKey. SQL * Description: If you want to modify the attribute of the table's primary key field, you need to delete the primary key and then recreate the primary key
) values (1, 3), (1, 7) on duplicate key update c = values (C );
After the execution, the value of C will change to 7 (the second repeat with the first repeat, and C will take the repeat value 7 directly ).Note: On duplicate key update is only a special MySQL syntax, not a standard
Insert on Dumplicate Update when the primary key is the same update, the contents of the update change to 1
Multiple contents of update are separated by commas ... And notmysql> insert INTO ' 200702 ' (' Domain ', ' 2nd_domain '
columns, change the column's order, index name, aggregation options, or fill factor for the PRIMARY key constraint. However, you cannot change the length of the column defined using the PRIMARY KEY constraint.
Attention:To modify a PRIMARY
');View field information for a tableDESC table name; Show columns from table name;View all information for a tableShow create table table name;Add a PRIMARY KEY constraintALTER TABLE name add constraint primary Key name (Shape: Pk_ table name) primary
Tags: style http color io strong for AR artAdd a table fieldALTER TABLE table1 add transactor varchar (ten) not Null;ALTER TABLE table1 add ID int unsigned not Null auto_increment primary keyModify the field type of a table and specify empty or non-emptyALTER TABLE name change field Name field Name field type [whether non-null allowed];ALTER TABLE name modify field Name field type [allow non-null];ALTER TABLE name modify field Name field type [allow n
SQL: the primary key of a data table is of the varchar type and does not increase itself. how can I insert a primary key when inserting data? SQL: the primary
Tags: primary key first break range Ror add comment art DropSQL PRIMARY KEY ConstraintThe PRIMARY KEY constraint uniquely identifies each record in a database table. The primary
further explained:
We need to modify the following SC table foreign key Declaration, add the name of the foreign key constraint, to facilitate our subsequent masking and recovery of foreign KEY constraints:
create table SC (s# integer , C # integer , Scor E integer , constraint sidfk foreign key (
:
We need to change the following SC table foreign key Declaration, add the name of the foreign key constraint, so that we might block and restore foreign KEY constraints:
create table SC (s# integer , C # integer , Score Span class= "Hljs-keyword" >integer , constraint sidfk foreign key (s#) referen
Tags: style http color io strong for AR Art Div www.169it.comAdd a table fieldALTER TABLE table1 add transactor varchar (ten) not Null;ALTER TABLE table1 add ID int unsigned not Null auto_increment primary keyModify the field type of a table and specify empty or non-emptyALTER TABLE name change field Name field Name field type [whether non-null allowed];ALTER TABLE name modify field Name field t
The last one we said about self-draining if the primary key is 0, here I figure out why, cause this is because the initial value is set in SQL for the self-row: From here you can see that the two variables, one is the increment of the initial value, one is incremental, here is 1, so when the setting of self-increment will be that field of the original existence
SQL: The primary key of a data table is a varchar type, does not increment, how to insert a primary key when inserting data
Reply content:
SQL: The primary
At the beginning of this demand, in the online search, found all said no, you have to delete the primary key column and then re-add or create a temporary table before the data, in fact, can be directly modified in MySQL.Modify the ID field to self-increment the primary key:ALTER TABLE ' Test ' change ' ID ' ' id ' int (one) UNSIGNED not NULL auto_increment, add
Tags: mysqlFirst describe the cause of this problem, suppose there is a table, which holds the trade orders, each order has a unique ID, the last update time, and the data, the details are as follows:+-------+----------+------+-----+---------------------+-------+ |field|type |Null|Key|Default
|extra| +-------+----------+------+-----+---------------------+-------+ |uid|int (11) |NO|PRI|0 | | |time|datetime|n
Create PROCEDURE pro_test (@userName NVARCHAR ( -) ) as--Select* from[dbo]. [Table_2]--SELECT *From [dbo]. [Student] Beginbegin TRAN DECLARE @tempTable TABLE (tempid uniqueidentifier) DECLARE @tempId uniqueidentifier INSERT into tabl E_2 (UserName) OUTPUT Inserted.userid into @tempTable VALUES (@userName)--insert data into the first table SELECT @tempId=tempid from @tempTable--assign a value to the middle variable INSERT into dbo. Student (Stuname, Stuage, Stusex,stucode) VALUES ('Zhansan',Ten,'
Data | database-building a database
Create DATABASE test;
Go
--Establish table customers
CREATE TABLE Customers (
ID int identity (1,1) not NULL,
Name varchar (15),
Age int,
Primary KEY (ID)
);
Go
--Establish the table orders
CREATE TABLE Orders (
ID int identity (1,1) not NULL,
Order_number varchar (15),
Price,
customer_id int,
Primary
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.