Skip to main content

Posts

SQL INSERT INTO statement with Examples

SQL INSERT INTO Statement The INSERT INTO statement is used to add new data to a database. The INSERT INTO statement adds a new record to a table. INSERT INTO can contain values for some or all of its columns. INSERT INTO can be combined with a SELECT to insert records. The SQL INSERT INTO syntax The general syntax is: 1) insert single row at a time on table INSERT INTO table-name (column-names) VALUES (values); or INSERT table-name (column-names) VALUES (values);  2) insert multiple row at a time INSERT INTO table-name (column-names) VALUES (values),(values),(values),.......; or INSERT table-name (column-names) VALUES (values),(values),(values),(values),.......;   SQL INSERT INTO Example 1) single row at a time mysql> insert into person(sno,name,age,sex) values ('3', 'chayan', 20, 'M'); Query OK, 1 row affected (0.01 sec) mysql> select *from person -> ; +-----+--------+------+------+ | sno | n

SQL Where Clause With examples

SQL WHERE Clause To limit the number of rows use the WHERE clause. The WHERE clause filters for rows that meet certain criteria. WHERE is followed by a condition that returns either true or false. WHERE is used with SELECT, UPDATE, and DELETE. The SQL WHERE syntax A WHERE clause with a SELECT statement: SELECT column-names FROM table-name WHERE condition A WHERE clause with an UPDATE statement: UPDATE table-name SET column-name = value WHERE condition A WHERE clause with a DELETE statement: DELETE table-name WHERE condition   SQL WHERE Clause Examples 1) with a select statement mysql> select name from person where age=26; +-----------------+ | name            | +-----------------+ | shantanu biswas | | sudip saha      | +-----------------+ 2 rows in set (0.00 sec) 2) with an update statement mysql> update person set sex='M' where age=25; Query OK, 0 rows affected (0.00 sec) Rows matched:

SQL select statement with example

SQL SELECT Statement The SELECT statement retrieves data from a database. The data is returned in a table-like structure called a result-set. SELECT is the most frequently used action on a database. The SQL SELECT syntax The general syntax is: SELECT column-names FROM table-name To select all columns use * SELECT * FROM table-name SQL SELECT Examples  1) select name from person(select one column)   mysql> select name from person; +-----------------+ | name            | +-----------------+ | subham ball     | | jit             | | sajal           | | sourav biswas   | | sajal           | | chayan das      | | shantanu biswas | | sudip saha      | | debo            | | NULL            | | NULL            | | mono            | | monojit         | +-----------------+ 2) select name,age from person(select multiple column) mysql> select name,age from person; +-----------------+------+ | name            | age  | +---------

Introduction to SQL and Database with example

            Introduction to SQL and Database What is SQL? SQL is a language used to retrieve and manipulate data in a RDMS. SQL stands for S tructured Q uery L anguage. What is a Database? A database is a place to store data. A relational database system (RDBMS) stores data in tables. Relational Database Tables A relational database stores data in tables. Each table has a number of rows and columns. The table below has 4 rows and 3 columns. SQL and Relational Databases A relational database contains tables which store data that is related in some way. SQL is the language that allows retrieval and manipulation of table data in a relational database.

SQL Basic Queries using Linux terminal

0) open mysql on terminal open terminal and type command sudo mysql entre password 1) Show Database mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | new                | | performance_schema | | sys                | +--------------------+ 5 rows in set (0.00 sec) 2) Change database mysql> use new; Database changed 3) Create Table  mysql> create table person(sno varchar(5) primary key, name varchar(20), age int(3), sex varchar(1)); Query OK, 0 rows affected (0.01 sec) 4) show Table mysql> show tables; +---------------+ | Tables_in_new | +---------------+ | person        | +---------------+ 1 row in set (0.00 sec) 5)Describe table mysql> describe person; +-------+-------------+------+-----+---------+-------+ | Field | Type        | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | sno  

Kleene Star Closure , Kleen Plus Operation and Recursive definition of languages

Kleene Star Closure Given Σ, then the Kleene Star Closure of the alphabet Σ, denoted by Σ * , is the collection of all strings defined over Σ, including Λ. It is to be noted that Kleene Star Closure can be defined over any set of strings. Examples If Σ = {x} Then Σ * = {Λ, x, xx, xxx, xxxx, ....} If Σ = {0,1} Then Σ * = {Λ, 0, 1, 00, 01, 10, 11, ....} If Σ = {aaB, c} Then Σ * = {Λ, aaB, c, aaBaaB, aaBc, caaB, cc, ....} Note Languages generated by Kleene Star Closure of set of strings, are infinite languages. (By infinite language, it is supposed that the language contains infinite many words, each of finite length). Kleen PLUS Operation ( + ) Kleen Plus Operation is same as Kleene Star Closure except that it does not generate Λ (null string), automatically. Example If Σ = {0,1} Then Σ + = {0, 1, 00, 01, 10, 11, ....} If Σ = {aab, c} Then Σ + = {aab, c, aabaab, aabc, caab, cc, ....} Remark It is to be noted that Kleene Star can also be operated on any str

Reverse of a String and Defining Languages and PALINDROME

Reverse of a String Definition : The reverse of a string s denoted by Rev(s) or s r , is obtained by writing the letters of s in reverse order. Example If s=abc is a string defined over Σ={a,b,c} then Rev(s) or s r = cba Example Σ= {B, aB, bab, d} s=BaBbabBd Rev(s)=dBbabaBB Defining Languages The languages can be defined in different ways , such as Descriptive definition, Recursive definition, using Regular Expressions(RE) and using Finite Automaton(FA) etc. Descriptive definition of language The language is defined, describing the conditions imposed on its words. Example The language L of strings of odd length, defined over Σ={a}, can be written as L={a, aaa, aaaaa,.....} Example The language L of strings that does not start with a, defined over Σ ={a,b,c}, can be written as L ={L, b, c, ba, bb, bc, ca, cb, cc, ...} Example The language L of strings of length 2, defined over Σ ={0,1,2}, can be written as L={00, 01, 02,10, 11,12,20,21,22} Example The lan