Found 4401 Articles for MySQL

How can we apply a NOT NULL constraint to a column of an existing MySQL table?

Jai Janardhan
Updated on 19-Jun-2020 11:27:51

284 Views

We can apply the NOT NULL constraint to a column of an existing MySQL table with the help of ALTER TABLE statement. SyntaxALTER TABLE table_name MODIFY colum_name datatype NOT NULL; Examplemysql> Create table test123(ID INT, Date DATE); Query OK, 0 rows affected (0.19 sec) mysql> Describe test123; +-------+---------+------+-----+---------+-------+ | Field | Type    | Null | Key | Default | Extra | +-------+---------+------+-----+---------+-------+ | ID    | int(11) | YES  |     | NULL    |       | | Date  | date    | YES  |     | NULL    |       | +-------+---------+------+-----+---------+-------+ ... Read More

What is MySQL NOT NULL constraint and how can we declare a field NOT NULL while creating a table?

Samual Sam
Updated on 19-Jun-2020 11:24:42

287 Views

Actually, MySQL NOT NULL constraint restricts a column of the table from having a NULL value. Once we applied NOT NULL constraint to a column, then we cannot pass a null value to that column. It cannot be declared on the whole table i.e., in other words, we can say that NOT NULL is a column level constraint.For declaring a field NOT NULL, we have to use NOT NULL keyword while defining the column in CREATE TABLE statement.Examplemysql> Create table Employee(ID Int NOT NULL, First_Name Varchar(20), Last_name Varchar(20), Designation Varchar(15)); Query OK, 0 rows affected (0.59 sec)In the query above, ... Read More

How to write Python CGI program to interact with MySQL?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:22

807 Views

suppose you want to login into you account using Python CGi script, below is the details login.html email: password: login.py #!C:\Python27\python.exe import MySQLdb import cgi import Cookie # Open database connection db = MySQLdb.connect("localhost", "root", "", "student" ) # prepare a ... Read More

How to insert a Python object in MySQL?

Rajendra Dharmkar
Updated on 28-Jan-2020 06:11:54

706 Views

Assuming that a MySQL database named 'test' is present on the server and a table named employee is also created. Let the table have five fields fname, lname, age, gender, and salary.Suppose we want to insert a tuple object containing data of a record defined as follows into the Msql database.t1=('Steven', 'Assange', 21, 'M', 2001)To establish an interface between MySQL and Python 3, you need to install the PyMySQL module. Then you can set up the connection using the following statementsimport PyMySQL # Open database connection db = PyMySQL.connect("localhost", "root", "", "test" ) # prepare a cursor object using cursor() ... Read More

How to store and retrieve a date into MySQL database using Python?

Rajendra Dharmkar
Updated on 28-Sep-2023 01:40:28

4K+ Views

To insert a date in a MySQL database, you need to have a column of Type date or datetime in your table. Once you have that, you'll need to convert your date in a string format before inserting it to your database. To do this, you can use the datetime module's strftime formatting function.Example from datetime import datetime now = datetime.now() id = 1 formatted_date = now.strftime('%Y-%m-%d %H:%M:%S') # Assuming you have a cursor named cursor you want to execute this query on: cursor.execute('insert into table(id, date_created) values(%s, %s)', (id, formatted_date))Running this will try to insert the tuple (id, date) ... Read More

How to convert Python date format to 10-digit date format for mysql?

Pranav Indukuri
Updated on 08-Sep-2022 06:59:26

1K+ Views

In this article, we will convert a python date format to 10-digit format for MySQL. We use the mktime() method from the time module provided by python. The mktime() method The python time method mktime() is the inverse function of the localtime(). The time.mktime() method of the Time module is used to convert a time.struct_time object or a tuple of 9 elements(which represents the time.struct_time object) to time in seconds since the epoch of the local system. Syntax The syntax of mktime() method is as follows. Time.mktime(t) Where, t is a time.struct_time object or a tuple containing 9 elements ... Read More

In SAP Business One SDK, filling a gridview and button saves in database

John SAP
Updated on 30-Jul-2019 22:30:20

292 Views

This can be achieved in multiple ways. You can either use a SAP DI documents, an open SQL or use data transfer workbench for this purpose.You can use a direct SQL write as this is one of straight way to do this. It is also possible to use SAP-DI Documents object to iterate over the Purchase Orders.One more option is using Data Transfer Workbench (DTW), where you export it to a file and then using DTW. It also provides error handling incase any exception occurs.

Getting memory error while doing UNION in SAP HANA

John SAP
Updated on 13-Dec-2019 06:45:39

190 Views

The SQL UNION clause/operator is used to combine the results of two or more SELECT statements without returning any duplicate rows.To use this UNION clause, each SELECT statement must haveThe same number of columns selectedThe same number of column expressionsThe same data type andHave them in the same orderWhile performing UNION you need to note that what data it will bring. To perform UNION ALL you need to ensure that views should be fully materialized.To know more about SAP HANA Modeling, you can refer SAP Guide:SAP HANA Guide

Getting error message: Scalar type not allowed in SAP HANA

karthikeya Boyini
Updated on 11-Dec-2019 08:57:53

426 Views

Few points about your code to create a Stored Procedure, that you can edit and tryPROCEDURE "SLT_DELETE"."HCDW.IT.IT::TO_TIMESTAMP_CALL" (IN IN_DATE DECIMAL(15),    OUT OUT_DATE TIMESTAMP)    LANGUAGE SQLSCRIPT AS    --DEFAULT SCHEMA    --READS SQL DATA AS BEGIN    select to_timestamp(IN_DATE) into OUT_DATE FROM DUMMY; END;In Line32, you have used below:SELECT: ORGID_ARTIKEL intoHowever correct syntax should be like:SELECT "ORGID_ARTIKEL" into

How to use SUM function for NUMC type field?

Johar Ali
Updated on 30-Jul-2019 22:30:20

451 Views

NUMC is numeric text. As this is text, SUM function cannot be implemented as it is of type varchar in the database.There is no simple solution to do it. The one method is to copy the data to internal tables, convert the NUMC data into DEC by looping through all the rows, SUM and GROUP them and then convert back the DEC values back to NUMC values.

Advertisements