1 ImportPymysql as PS2 3 #Open a database connection4db = Ps.connect (host='localhost', user='Root', password='123456', database='Test', charset='UTF8')5 6 #Create a Cursor object7Cur =db.cursor ()8 9 #parametric processingTensql ="INSERT into USER (Name,password) VALUES (%s,%s)" One ACur.execute (SQL, ('Little Black','123456')) - - Print("OK") the - #Commit the transaction (this must be actively committed, otherwise in the database operation incre
, so it is not necessary to remove the duplicate rows and arbitrarily use DISTINCT, but should first understand whether the data used may contain duplicate rows, To reduce the need to use distinct.6. SQL if the string with wildcards still does not provide enough flexibility, you can use a regular expression.Find records with names beginning with F or GMysql:select * from EMP where name REGEXP ' ^[FG] 'Oracle uses regexp_like and
name set column name = expression [...,]WHERE ConditionExample:Update score set classid=1821 where classid=1823 Change 1823 to 1821(Can have logical representations of and and or )(4) Inquiry recordGrammar:Selcet column 1 [, column 2,...]From table nameWHERE ConditionGROUP BY grouping expressionsHaving group statistics conditionsOredr by sort expressionExample:Example 1: Querying the basic information of all studentsSelect * FROM StudentExample 2: Check the test scores of all students and
,getdate ()-birthFrom Is_studentwhere GETDATE ()-birth >20(5) A view with an expressionDefines a view of a student's year of birth, including number, name, and year of birthCreate View bt_s (Studentid,studentname,birth)AsSelect Studentid,studentname,getdate ()-birthFrom student(6) Views with grouped statistics:Define a view of each student's academic number and average scoreCreate View S_g (Studentid,grade)AsSelect Studentid,avg (Grade)From gradeGROUP BY StudentID2. Modify the View:Alter VIEW vi
>alter table Pet drop weight; change column ALTER TABLE tbl_name modify Col_name type For example, change the types of weight: mysql> ALTER TABLE pet Modify weight SAMLL int Another method is: ALTER TABLE tbl_name change old_col_name col_name type For example: mysql> ALTER TABLE pet change weigh T weight samllint; Renaming the column Mysql>alter table pet Change weight wei; Rename table ALTER TABLE tbl_name rename NEW_TBL For example, rename the pet table to animal Mysql>al
was designed without consideration and NBSP; IISNBSP; used together. However, a localdb database can be easily migrated to SQLNBSP;SERVERNBSP; or NBSP, sqlazure In Visual Studio(or ),Visual Studio installs the default LocalDB . By default, theEntity Framework looks for a database connection with the same name as the object context class (Moviedbcontext in this project ). Open the Web. config file for the application's root directory (not in the Views directory, web. config). F
Last time we introduced:SQL/PLUS Study NotesThis section describes the SQL/PLUS learning notes.Edit the current line command in the bufferNext, let's take a look at this part.
(1). change (enable you to change the current line)
First, use the list command to change the current line (or directly enter the row number, and press enter to change the current line ):
SQL
to be completely isolated, a bit of concurrency ...). Therefore, SQL Server's default read commited is a good choice to strike a balance between isolation and concurrency.SQL Server passes the lock, just like a traffic light at a crossroads, to tell all concurrent connections that at the same time those resources can be read and those resources can be modified. As mentioned earlier, the query itself is not a gentleman, so it needs to be supervised. W
Label:Stored procedures: SQL Server Stored Procedures Blog Park on an article, explained in very detailed, there are test code, very practical. Execute dynamic SQL statements in SQL Server stored procedures The curse and blessings of the dynamically SQL stored procedures and Cursors
Label:1.DISTINCT DISTINCT This keyword is used to filter out redundant duplicate records to keep only one, but it is often used only to return the number of distinct records, rather than using it to return all values that are not re-recorded. The reason is that distinct only with double-loop query to solve, and so for a very large number of stations, will undoubtedly directly affect the efficiency. The 2.ORDER by order BY statement is used to sort the result set based on the specified column. T
Label:1.Top Query Statements SELECT TOP n Used to get the number of data bars returned by the rule. SELECT TOP N PERCENT 2.LIKE operator Query the records in the database by using a wildcard character. _ Denotes matching with any single character % indicates a match to a string containing one or more characters [] matches any single character in a specific range (for example, [a-f]) or a specific set (for example, [abcdef]). [^] or [!] Matches any single character other than a specific range (
table
As a table example select E.emono,e.ename from (SELECT * from where deptno=30) E
gave the table an alias E
As a condition there are several situations
Single-column: You can use =,>,
A multiline column (collection) can be
Single-row multi-column (object) is a row, like an object, what property has
Multiline multiple columns: Multiple rows and columns are always used as tables from behind
Single-row Example: SELECT * from emp where sal > (select
),
-)+'1')
--3. The first or last day of the month in which the specified date is located
--A. First day of the monthSelectconvert (datetime,CONVERT(Char(8),@dt, -)+'1')
--B. The last day of the monthSelectdateadd ( Day,-1,CONVERT(Char(8),DATEADD(Month,1,@dt), -)+'1')
--C. Last day of the month (easy-to-use error method)Selectdateadd (Month,1,DATEADD( Day,- Day(@dt),@dt))
--4. Any day of the week on which the specified date is locatedSelectdateadd ( Day,@number-DATEPART(Weekday,@d
unique (name)4. Invalidating a constraintThe Emp3 table has a unique constraint that invalidates it, but does not deletesql> ALTER TABLE Emp3 2 disable constraint emp3_email_uk;5. Effective, if the data of the column should conform to the constraints of the constrained constraint, such as the unique constraint, in order to be effective, it is necessary to ensure that the data of this column cannot be duplicated.sql> ALTER TABLE Emp3 2 enable constraint Emp3_email_uk; 6. Query constraintsSEL
results of multiple SELECT statements together, in which case it is necessary to combine the results of several SELECT statements, for example, to query all the employee information of company A and Company B, and then merge the results of the two queries together. The Union and UNION ALL keywords are used for the merge operation. Format: SELECT statement 1 UNION | UNION All SELECT statement 2 UNION | UNION All ............ Example: Query the value of the d_id field from the Department table a
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.